我有一个在项目之间共享的SQLConnection,如果它从一个ini文件中读取配置,是否有一些方法可以在设计时加载相同的配置?有没有办法在设计时从ini文件中加载TSQLConnection参数?
1
A
回答
3
一种方法是编写您自己的TSQLConnection后代。
0
我假设你正在使用德尔福2009年或2010年。你可以参考我的博客文章第一:http://chee-yang.blogspot.com/2008/09/delphi-2009-using-dbx4-framework.html
我跟踪这个问题相当长的一段时间。文章中提出了很多QC报告。一些已经在德尔福2010年解决。请先看看,我们可能会在后期讨论。
3
你必须为它创建自己的自定义组件,我们称之为TCustomSQLConnection。只需将这个组件放在表单或数据模块上,将一个名为ConfigurationFile的自定义属性设置到您的ini文件中,然后您就可以开始使用了。如果我理解正确,这就是你想要的 - 如果不是我的appologies。
请看看下面的代码,
unit uSQLCustomConnection; interface uses SysUtils, Classes, DB, SqlExpr; type TCustomSQLConnection = class(TSQLConnection) private FConfigurationFile : String; procedure SetConfigurationFile(Value: TStrings); procedure LoadConfiguration(AConfigurationFile: String); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property ConfigurationFile : String read FConfigurationFile write SetConfigurationFile; end; procedure Register; implementation constructor TCustomSQLConnection.Create(AOwner: TComponent); begin inherited; FConfigurationFile := ''; end; destructor TCustomSQLConnection.Destroy; begin // free memory if needed inherited; end; procedure TCustomSQLConnection.SetConfigurationFile(Value: String); begin FConfigurationFile := Value; if FileExists(FConfigurationFile) then LoadConfiguration(FConfigurationFile); end; procedure TCustomSQLConnection.LoadConfiguration(AConfigurationFile: String); begin // Put the code that loads the configuration here end; procedure Register; begin RegisterComponents('Samples', [TCustomSQLConnection]); end; end.
所有你需要做的就是将自己的代码加载配置后安装该组件,你是好去。
我会把这个组件放在一个数据模块上,以及一些在项目之间共享的其他组件。
希望它有帮助。
相关问题
- 1. 没有INI文件被加载(php.ini中)
- 2. 有没有办法从流中加载Crystal Report 9.0文件?
- 3. 有没有办法从HTML文件(在Firefox插件main.js文件中)加载AngularJS?
- 4. 有没有办法在java中加载gz文件?
- 5. 有没有办法在Perl中加载配置文件?
- 6. 有没有办法在JVM中查找加载的类文件?
- 7. 有没有办法在Python中重新加载“当前”文件?
- 8. 有没有办法在jquery中设置一个计时器
- 9. 有没有办法从卸载程序文件中禁用autouninstaller?
- 10. 有没有办法在iOS下载时播放MP3文件?
- 11. 有没有办法从文件中加载Maven Surefire插件排除列表?
- 12. 有没有办法在PHP PDO中设置一个参数?
- 13. 有没有办法让JavaScript文件在AIR中加载另一个文件?
- 14. 在Chef中,有没有办法从子目录加载属性?
- 15. 有没有办法从变量设置模板参数?
- 16. 有没有办法从jQuery实时加载特定功能?
- 17. 有没有办法在javaFX中加载Eclipse RCP插件?
- 18. 有没有办法参数化在Dojo中加载哪些模块?
- 19. 有没有办法从PHP代码加载的文件中解析PHP?
- 20. 有没有办法在运行时将类文件加载到程序集?
- 21. 有没有办法从HDFS加载数据到cassandra?
- 22. 有没有办法从iOS中的plist中加载const unsigned char?
- 23. 有没有办法加载关于分辨率的CSS文件?
- 24. 有没有办法加载配置文件?
- 25. 有没有办法让Winforms控件的属性在设计时有不同的表现(在VS设计器中)?
- 26. 有没有办法不加载jQuery?
- 27. 有没有办法在python中重载+ =?
- 28. 有没有办法从FilterGraph卸载文件
- 29. 有没有办法加载json文件以及所有其他js文件?
- 30. 有没有办法从数据库中过期文件?
我想你不明白我的问题。我想在设计时加载设置,我可以在设计时连接到数据库的唯一方法是通过在dfm中配置连接,但我不想这样做。 – 2009-10-30 11:50:33