ODAC+SDAC源代码
源代码在线查看: myconnectform.pas
unit MyConnectForm;
interface
uses
{$IFDEF LINUX}
SysUtils, Types, Classes, QGraphics, QControls, QForms, QDialogs, QStdCtrls,
QComCtrls, QExtCtrls, QGrids, QDBGrids, OdacClx, QButtons, QMask,
{$ELSE}
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Mask, Buttons, OdacVcl,
{$ENDIF}
Ora, OraError;
type
TfmMyConnect = class(TForm)
Panel: TPanel;
lbUsername: TLabel;
lbPassword: TLabel;
lbServer: TLabel;
edUsername: TEdit;
edPassword: TMaskEdit;
edServer: TComboBox;
btConnect: TBitBtn;
btCancel: TBitBtn;
Bevel1: TBevel;
procedure btConnectClick(Sender: TObject);
private
FConnectDialog: TConnectDialog;
FRetries: integer;
FRetry: boolean;
procedure SetConnectDialog(Value:TConnectDialog);
protected
procedure DoInit; virtual;
procedure DoConnect; virtual;
public
published
property ConnectDialog:TConnectDialog read FConnectDialog write SetConnectDialog;
end;
var
fmMyConnect: TfmMyConnect;
implementation
{$R *.dfm}
procedure TfmMyConnect.DoInit;
begin
FRetry := False;
FRetries := FConnectDialog.Retries;
Caption := FConnectDialog.Caption;
lbUsername.Caption := FConnectDialog.UsernameLabel;
lbPassword.Caption := FConnectDialog.PasswordLabel;
lbServer.Caption := FConnectDialog.ServerLabel;
btConnect.Caption := FConnectDialog.ConnectButton;
btCancel.Caption := FConnectDialog.CancelButton;
FConnectDialog.GetServerList(edServer.Items);
edUsername.Text := FConnectDialog.Session.Username;
edPassword.Text := FConnectDialog.Session.Password;
edServer.Text := FConnectDialog.Session.Server;
if (edUsername.Text '') and (edPassword.Text = '') then
ActiveControl := edPassword;
end;
procedure TfmMyConnect.DoConnect;
begin
FConnectDialog.Session.Password := edPassword.Text;
FConnectDialog.Session.Server := edServer.Text;
FConnectDialog.Session.UserName := edUsername.Text;
try
FConnectDialog.Connection.PerformConnect(FRetry);
ModalResult := mrOk;
except
on E:EOraError do begin
Dec(FRetries);
FRetry := True;
if FRetries = 0 then
ModalResult := mrCancel;
case E.ErrorCode of
1005: ActiveControl := edPassword;
1017: if ActiveControl edUsername then ActiveControl := edPassword;
12203,12154: ActiveControl := edServer;
end;
raise;
end
else
raise;
end;
end;
procedure TfmMyConnect.SetConnectDialog(Value:TConnectDialog);
begin
FConnectDialog := Value;
DoInit;
end;
procedure TfmMyConnect.btConnectClick(Sender: TObject);
begin
DoConnect;
end;
initialization
if GetClass('TfmMyConnect') = nil then
Classes.RegisterClass(TfmMyConnect);
end.