udata.pas

来自「Crlab公司用来连接MySQL数据库的控件」· PAS 代码 · 共 76 行

PAS
76
字号
unit uData;

interface

uses
  SysUtils, Classes, DB, DBAccess, MyAccess, MemData;

type
  TDM = class(TDataModule)
    Connection: TMyConnection;
    procedure ConnectionConnectionLost(Sender: TObject; Component: TComponent;
      ConnLostCause: TConnLostCause; var RetryMode: TRetryMode);
    procedure ConnectionBeforeConnect(Sender: TObject);
    procedure ConnectionAfterConnect(Sender: TObject);
    procedure ConnectionAfterDisconnect(Sender: TObject);
  end;

implementation

{$R *.dfm}

uses IWInit, ServerController;

{ TDM }

procedure TDM.ConnectionBeforeConnect(Sender: TObject);
begin
  Connection.Username := UserSession.Username;
  Connection.Password := UserSession.Password;
  Connection.Server := UserSession.Server;
  Connection.Database := UserSession.Database;
  Connection.Options.DisconnectedMode := UserSession.DisconnectedMode;
  Connection.Pooling := UserSession.Pooling;
  Connection.PoolingOptions := UserSession.PoolingOptions;
  if UserSession.FailOver then
    Connection.OnConnectionLost := ConnectionConnectionLost
  else
    Connection.OnConnectionLost := nil;
end;

procedure TDM.ConnectionAfterConnect(Sender: TObject);
begin
  UserSession.IsGoodConnection := True;
  UserSession.ConnectionResult := 'Connected';
end;

procedure TDM.ConnectionAfterDisconnect(Sender: TObject);
begin
  if not (csDestroying in Connection.ComponentState) then
    UserSession.ConnectionResult := '';
end;

procedure TDM.ConnectionConnectionLost(Sender: TObject; Component: TComponent;
  ConnLostCause: TConnLostCause; var RetryMode: TRetryMode);
var
  Msg: string;
begin
  UserSession.IsGoodConnection := False;
  case ConnLostCause of
    clUnknown:
      Msg := 'Unknown';
    clConnect:
      Msg := 'Connect';
    clExecute:
      Msg := 'Execute';
    clOpen:
      Msg := 'Open';
    clApply:
      Msg := 'Apply';
  end;
  UserSession.ConnectionResult := 'Connection lost: ' +
    Component.Name + ' - ' + Msg;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?