⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myconnectform.pas

📁 ODAC 5.7.0.28
💻 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.

⌨️ 快捷键说明

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