FireDAC ResultConnectionDef 和有关 Server 和 Port 的信息
FireDAC ResultConnectionDef and information about Server and Port
DelphiXE 10.2.2
正在检查这里 old http://codeverge.com topic 当时工作的地方,但现在
ResultConnectionDef 用于获取有关已建立连接(服务器和端口)的信息。
procedure TMainForm.UpdateCaption;
begin
Caption := Format('Truice %s - Connection: %s:%d / %s', [VERSION_EXE, MyTrinityConnection.HostName, MyTrinityConnection.Port, GetDBVersion]);
Application.Title := Caption;
end;
使用 FireDac:
uses FireDAC.Phys.MySQLDef, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MySQL, FireDAC.VCLUI.Wait, FireDAC.Comp.UI, FireDAC.Comp.Client, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet, FireDAC.Comp.Script, FireDAC.Comp.ScriptCommands, FireDAC.Stan.Util;
procedure TMainForm.UpdateCaption;
begin
Caption := Format('Truice %s - Connection: %s:%d / %s', [VERSION_EXE, MyTrinityConnection.ResultConnectionDef.Server, MyTrinityConnection.ResultConnectionDef.Port, GetDBVersion]);
Application.Title := Caption;
end;
结果:
'IFDStanConnectionDef' does not contain a member named 'Server'
'IFDStanConnectionDef' does not contain a member named 'Port'
问题:
- FireDAC 是否有更改此部分的任何更改?
- 为活动连接收集服务器和端口的最佳方法是什么?
维多利亚解决方案后的最终代码,看起来是这样的:
procedure TMainForm.UpdateCaption;
var
Server: string;
Port: Integer;
begin
Server := TFDPhysMySQLConnectionDefParams(MyTrinityConnection.ResultConnectionDef.Params).Server;
Port := TFDPhysMySQLConnectionDefParams(MyTrinityConnection.ResultConnectionDef.Params).Port;
Caption := Format('Truice %s - Connection: %s:%d / %s', [VERSION_EXE, Server, Port, GetDBVersion]);
Application.Title := Caption;
end;
1。 FireDAC 是否在这部分进行了更改?
是的,已更改。底层接口的旧变体 (IADStanConnectionDef) 具有 Server 和 Port 等属性。这个界面的新版本
(IFDStanConnectionDef) 发布指向特定 DBMS 参数集合实现的 Params 属性。
更改的原因可能是支持的 DBMS 种类繁多(其中一些没有远程连接)。
2。如何获取活动 MySQL 连接的服务器和端口?
至少有两种方法可以获取我所知道的活动 MySQL 连接的服务器和端口。第一个是使用提到的 ResultConnectionDef 及其 Params 属性 (假定两个示例中的 FDConnection1 对象已连接MySQL 服务器),例如:
uses
FireDAC.Phys.MySQLDef;
var
Port: Integer;
Server: string;
begin
Port := TFDPhysMySQLConnectionDefParams(FDConnection1.ResultConnectionDef.Params).Port;
Server := TFDPhysMySQLConnectionDefParams(FDConnection1.ResultConnectionDef.Params).Server;
...
end;
MySQL 的另一个选项是从 TMySQLSession 会话对象获取这些信息,例如:
uses
FireDAC.Phys.MySQLWrapper;
var
Port: Cardinal;
Server: string;
begin
Port := TMySQLSession(FDConnection1.ConnectionIntf.CliObj).Port;
Server := TMySQLSession(FDConnection1.ConnectionIntf.CliObj).Host;
...
end;
以上两种方式(此时)相等,因为在内部 TMySQLSession 从连接定义参数中接收主机和端口(这意味着你设置的就是你得到的,就像 ZEOS 对它们的属性所做的一样) .
DelphiXE 10.2.2
正在检查这里 old http://codeverge.com topic 当时工作的地方,但现在
ResultConnectionDef 用于获取有关已建立连接(服务器和端口)的信息。
procedure TMainForm.UpdateCaption;
begin
Caption := Format('Truice %s - Connection: %s:%d / %s', [VERSION_EXE, MyTrinityConnection.HostName, MyTrinityConnection.Port, GetDBVersion]);
Application.Title := Caption;
end;
使用 FireDac:
uses FireDAC.Phys.MySQLDef, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MySQL, FireDAC.VCLUI.Wait, FireDAC.Comp.UI, FireDAC.Comp.Client, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet, FireDAC.Comp.Script, FireDAC.Comp.ScriptCommands, FireDAC.Stan.Util;
procedure TMainForm.UpdateCaption;
begin
Caption := Format('Truice %s - Connection: %s:%d / %s', [VERSION_EXE, MyTrinityConnection.ResultConnectionDef.Server, MyTrinityConnection.ResultConnectionDef.Port, GetDBVersion]);
Application.Title := Caption;
end;
结果:
'IFDStanConnectionDef' does not contain a member named 'Server'
'IFDStanConnectionDef' does not contain a member named 'Port'
问题:
- FireDAC 是否有更改此部分的任何更改?
- 为活动连接收集服务器和端口的最佳方法是什么?
维多利亚解决方案后的最终代码,看起来是这样的:
procedure TMainForm.UpdateCaption;
var
Server: string;
Port: Integer;
begin
Server := TFDPhysMySQLConnectionDefParams(MyTrinityConnection.ResultConnectionDef.Params).Server;
Port := TFDPhysMySQLConnectionDefParams(MyTrinityConnection.ResultConnectionDef.Params).Port;
Caption := Format('Truice %s - Connection: %s:%d / %s', [VERSION_EXE, Server, Port, GetDBVersion]);
Application.Title := Caption;
end;
1。 FireDAC 是否在这部分进行了更改?
是的,已更改。底层接口的旧变体 (IADStanConnectionDef) 具有 Server 和 Port 等属性。这个界面的新版本 (IFDStanConnectionDef) 发布指向特定 DBMS 参数集合实现的 Params 属性。
更改的原因可能是支持的 DBMS 种类繁多(其中一些没有远程连接)。
2。如何获取活动 MySQL 连接的服务器和端口?
至少有两种方法可以获取我所知道的活动 MySQL 连接的服务器和端口。第一个是使用提到的 ResultConnectionDef 及其 Params 属性 (假定两个示例中的 FDConnection1 对象已连接MySQL 服务器),例如:
uses
FireDAC.Phys.MySQLDef;
var
Port: Integer;
Server: string;
begin
Port := TFDPhysMySQLConnectionDefParams(FDConnection1.ResultConnectionDef.Params).Port;
Server := TFDPhysMySQLConnectionDefParams(FDConnection1.ResultConnectionDef.Params).Server;
...
end;
MySQL 的另一个选项是从 TMySQLSession 会话对象获取这些信息,例如:
uses
FireDAC.Phys.MySQLWrapper;
var
Port: Cardinal;
Server: string;
begin
Port := TMySQLSession(FDConnection1.ConnectionIntf.CliObj).Port;
Server := TMySQLSession(FDConnection1.ConnectionIntf.CliObj).Host;
...
end;
以上两种方式(此时)相等,因为在内部 TMySQLSession 从连接定义参数中接收主机和端口(这意味着你设置的就是你得到的,就像 ZEOS 对它们的属性所做的一样) .