Delphi 是否有某种方法可以在设计时从ini文件加载TSQLConnection参数?

Delphi 是否有某种方法可以在设计时从ini文件加载TSQLConnection参数?,delphi,ide,Delphi,Ide,我有一个项目间共享的SQLConnection,在runtine中,它从ini文件读取配置,有什么方法可以在设计时加载相同的配置吗?一种方法是编写您自己的TSQLConnection子代。一种方法是编写您自己的TSQLConnection子代。我假设您使用的是Delphi 2009或2010。您可以先参考我的博客文章: 我跟踪这个问题已经有一段时间了。文中提出了不少质量控制报告。有些问题已在Delphi 2010中解决。请先看一看,我们可以在后面讨论。我假设您使用的是Delphi 2009或20

我有一个项目间共享的SQLConnection,在runtine中,它从ini文件读取配置,有什么方法可以在设计时加载相同的配置吗?

一种方法是编写您自己的TSQLConnection子代。

一种方法是编写您自己的TSQLConnection子代。

我假设您使用的是Delphi 2009或2010。您可以先参考我的博客文章:


我跟踪这个问题已经有一段时间了。文中提出了不少质量控制报告。有些问题已在Delphi 2010中解决。请先看一看,我们可以在后面讨论。

我假设您使用的是Delphi 2009或2010。您可以先参考我的博客文章:


我跟踪这个问题已经有一段时间了。文中提出了不少质量控制报告。有些问题已在Delphi 2010中解决。请先看一看,我们可能会在后面讨论。

您必须为它创建自己的自定义组件,我们称之为TCustomSQLConnection。只需将此组件放到表单或数据模块上,在ini文件中设置一个名为ConfigurationFile的自定义属性,就可以了。如果我理解正确,这就是你想要的——如果不是我的任命

请看下面的代码

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. 单元连接; 接口 使用 SysUtils、Classes、DB、SqlExpr; 类型 TCustomSQLConnection=class(TSQLConnection) 私有的 FConfigurationFile:字符串; 程序SetConfigurationFile(值:TStrings); 过程加载配置(配置文件:字符串); 公众的 构造函数创建(AOwner:TComponent);推翻 毁灭者毁灭;推翻 出版 属性配置文件:字符串读取FConfigurationFile写入SetConfigurationFile; 结束; 程序登记册; 实施 构造函数TCustomSQLConnection.Create(AOwner:TComponent); 开始 继承; FConfigurationFile:=''; 结束; 析构函数TCustomSQLConnection.Destroy; 开始 //如果需要,请释放内存 继承; 结束; 过程TCustomSQLConnection.SetConfigurationFile(值:字符串); 开始 FConfigurationFile:=值; 如果文件存在(FConfigurationFile),则 加载配置(FConfigurationFile); 结束; 过程TCustomSQLConnection.LoadConfiguration(一个配置文件:字符串); 开始 //将加载配置的代码放在这里 结束; 程序登记册; 开始 注册表组件('Samples',[TCustomSQLConnection]); 结束; 结束。 您所要做的就是在添加您自己的加载配置的代码之后安装这个组件,您就可以开始了

我将把这个组件放在一个数据模块上,以及一些在项目之间共享的其他组件


希望能有所帮助。

您必须为其创建自己的自定义组件,我们称之为TCustomSQLConnection。只需将此组件放到表单或数据模块上,在ini文件中设置一个名为ConfigurationFile的自定义属性,就可以了。如果我理解正确,这就是你想要的——如果不是我的任命

请看下面的代码

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. 单元连接; 接口 使用 SysUtils、Classes、DB、SqlExpr; 类型 TCustomSQLConnection=class(TSQLConnection) 私有的 FConfigurationFile:字符串; 程序SetConfigurationFile(值:TStrings); 过程加载配置(配置文件:字符串); 公众的 构造函数创建(AOwner:TComponent);推翻 毁灭者毁灭;推翻 出版 属性配置文件:字符串读取FConfigurationFile写入SetConfigurationFile; 结束; 程序登记册; 实施 构造函数TCustomSQLConnection.Create(AOwner:TComponent); 开始 继承; FConfigurationFile:=''; 结束; 析构函数TCustomSQLConnection.Destroy; 开始 //如果需要,请释放内存 继承; 结束; 过程TCustomSQLConnection.SetConfigurationFile(值:字符串); 开始 FConfigurationFile:=值; 如果文件存在(FConfigurationFile),则 加载配置(FConfigurationFile); 结束; 过程TCustomSQLConnection.LoadConfiguration(一个配置文件:字符串); 开始 //将加载配置的代码放在这里 结束; 程序登记册; 开始 注册表组件('Samples',[TCustomSQLConnection]); 结束; 结束。 您所要做的就是在添加您自己的加载配置的代码之后安装这个组件,您就可以开始了

我将把这个组件放在一个数据模块上,以及一些在项目之间共享的其他组件


希望有帮助。

我想你不明白我的问题。我想在设计时加载设置,在设计时连接数据库的唯一方法是在dfm中配置连接,我不想这样做。我想你不明白我的问题。我想在设计时加载设置,在设计时连接数据库的唯一方法是在dfm中配置连接,我不想这样做。