我有一个在项目之间共享的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. 有没有办法从流中加载Crystal Report 9.0文件?
- 2. 有没有办法在设计的登录功能中通过超时参数?
- 3. 有没有办法在Perl中加载配置文件?
- 4. 有没有办法在Python中重新加载“当前”文件?
- 5. 有没有办法在java中加载gz文件?
- 6. 有没有办法从卸载程序文件中禁用autouninstaller?
- 7. 有没有办法在PHP PDO中设置一个参数?
- 8. 有没有办法让JavaScript文件在AIR中加载另一个文件?
- 9. 有没有办法从变量设置模板参数?
- 10. 有没有办法在javaFX中加载Eclipse RCP插件?
- 11. 有没有办法在运行时将类文件加载到程序集?
- 12. 有没有办法从iOS中的plist中加载const unsigned char?
- 13. 有没有办法加载关于分辨率的CSS文件?
- 14. 有没有办法让Winforms控件的属性在设计时有不同的表现(在VS设计器中)?
- 15. 有没有办法不加载jQuery?
- 16. 有没有办法在python中重载+ =?
- 17. 有没有办法在运行时加载类jar和包?
- 18. 有没有办法在Apache中预加载代码在PHP中?
- 19. 有没有办法从.java文件中获取.class文件
- 20. 有没有办法从AliasMatch中免除文件/文件夹?
- 21. 有没有办法省略掉参数?
- 22. 有没有办法在Silverlight中没有Webclient的情况下下载文件?
- 23. 有没有办法从内存文件处理程序加载图标?
- 24. 有没有办法从XMLHttpRequest响应中获取参数?
- 25. 有没有办法从make调用中获取-j参数?
- 26. 有没有办法从ActionScript中检查循环参数的值?
- 27. 有没有办法从库中读取命令行参数?
- 28. django manage.py - 有没有办法从环境中获取--settings参数?
- 29. 有没有办法从组件中继承.config文件中的设置?
- 30. 有没有办法将大文本文件逐行加载到kdb中?
我想你不明白我的问题。我想在设计时加载设置,我可以在设计时连接到数据库的唯一方法是通过在dfm中配置连接,但我不想这样做。 – 2009-10-30 11:50:33