unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, AppEvnts;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ApplicationEvents1: TApplicationEvents;
procedure ADOConnection1WillConnect(Connection: TADOConnection;
var ConnectionString, UserID, Password: WideString;
var ConnectOptions: TConnectOption; var EventStatus: TEventStatus);
procedure ApplicationEvents1Exception(Sender: TObject; E: Exception);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
Dont_Init_ADO: Boolean = True;implementation{$R *.dfm}procedure TForm1.ADOConnection1WillConnect(Connection: TADOConnection;
var ConnectionString, UserID, Password: WideString;
var ConnectOptions: TConnectOption; var EventStatus: TEventStatus);
begin
if Dont_Init_ADO = True then
EventStatus := esCancel;
end;procedure TForm1.ApplicationEvents1Exception(Sender: TObject; E: Exception);
begin
if E.ClassName = 'EOleException' then
Begin
//
End else
Begin
Showmessage(E.ClassName + #13 + E.Message);
End;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ApplicationEvents1.Free;
Dont_Init_ADO := False;
ADOConnection1.ConnectionString := 'MyConnectionString';
ADOConnection1.Connected := True;
end;
end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, AppEvnts;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ApplicationEvents1: TApplicationEvents;
procedure ADOConnection1WillConnect(Connection: TADOConnection;
var ConnectionString, UserID, Password: WideString;
var ConnectOptions: TConnectOption; var EventStatus: TEventStatus);
procedure ApplicationEvents1Exception(Sender: TObject; E: Exception);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
Dont_Init_ADO: Boolean = True;implementation{$R *.dfm}procedure TForm1.ADOConnection1WillConnect(Connection: TADOConnection;
var ConnectionString, UserID, Password: WideString;
var ConnectOptions: TConnectOption; var EventStatus: TEventStatus);
begin
if Dont_Init_ADO = True then
EventStatus := esCancel;
end;procedure TForm1.ApplicationEvents1Exception(Sender: TObject; E: Exception);
begin
if E.ClassName = 'EOleException' then
Begin
//
End else
Begin
Showmessage(E.ClassName + #13 + E.Message);
End;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ApplicationEvents1.Free;
Dont_Init_ADO := False;
ADOConnection1.ConnectionString := 'MyConnectionString';
ADOConnection1.Connected := True;
end;
end.
建立數據庫連接,不過這個連接參數還沒有寫。
ApplicationEvents1 這個主要是用來載獲當前APPLICATION的事件,異常這些。
主要就是这两句 ADOConnection1.ConnectionString := 'MyConnectionString';//设置连接字符串
ADOConnection1.Connected := True;//连接
procedure ApplicationEvents1Exception //获取异常信息
——php版块太难混了,挣个分不易