Own logindialog will not work
Posted: Wed 15 Oct 2008 08:12
I created my own Connectdialog with the specifications I saw in the MyDACDemo. I made a example to test the connection. Compiling is not the problem, but on running the example it comes with a runtime error on this line
This is my dialog:
I can't see what I'm doing wrong.
Is this the only way to create an own Connectdialog
Code: Select all
MyConnection1.ConnectDialog.DialogClass := 'TThemconnectDialogFrm';
Code: Select all
unit ThemConnectDialog;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, MyClasses, MyAccess, MyCall, MyDACVCL;
type
TThemconnectDialogFrm = class(TForm)
LblGebruiker: TLabel;
EGebruiker: TEdit;
EWachtwoord: TEdit;
LblWachtwoord: TLabel;
CBDatabase: TComboBox;
CBserver: TComboBox;
EPort: TEdit;
LblDatabase: TLabel;
LblServer: TLabel;
LblPoortnummer: TLabel;
BtnConnect: TBitBtn;
BtnCancel: TBitBtn;
procedure BtnConnectClick(Sender: TObject);
private
{ Private declarations }
FConnectDialog: TMyConnectDialog;
FRetries:integer;
FRetry: boolean;
procedure SetConnectDialog(Value: TMyConnectDialog);
protected
procedure DoInit; virtual;
procedure DoConnect; virtual;
public
published
property ConnectDialog: TMyConnectDialog read FConnectDialog write SetConnectDialog;
end;
var
ThemconnectDialogFrm: TThemconnectDialogFrm;
implementation
{$R *.dfm}
procedure TThemconnectDialogFrm.BtnConnectClick(Sender: TObject);
begin
DoConnect;
end;
procedure TThemconnectDialogFrm.DoConnect;
begin
FConnectDialog.Connection.Password := eWachtwoord.Text;
FConnectDialog.Connection.Server := CBServer.Text;
FConnectDialog.Connection.UserName := eGebruiker.Text;
(FConnectDialog.Connection as TMyConnection).Port := StrToInt(ePort.Text);
FConnectDialog.Connection.Database := CBDatabase.Text;
try
FConnectDialog.Connection.PerformConnect(FRetry);
ModalResult := mrOk;
except
on E: EMyError do begin
Dec(FRetries);
FRetry := True;
if FRetries = 0 then
ModalResult := mrCancel;
if E.ErrorCode = CR_CONN_HOST_ERROR then
ActiveControl := CBServer
else
if E.ErrorCode = ER_ACCESS_DENIED_ERROR then
if ActiveControl eGebruiker then
ActiveControl := eWachtwoord;
raise;
end
else
raise;
end;
end;
procedure TThemconnectDialogFrm.DoInit;
begin
FRetry := False;
FRetries := FConnectDialog.Retries;
FConnectDialog.GetServerList(CBServer.Items);
eGebruiker.Text := FConnectDialog.Connection.Username;
eWachtwoord.Text := FConnectDialog.Connection.Password;
CBServer.Text := FConnectDialog.Connection.Server;
EPort.Text := '3306';
CBDatabase.Text := 'bolmate';
CBServer.Text := 'router9';
if (eGebruiker.Text '') and (eWachtwoord.Text = '') then
ActiveControl := eWachtwoord;
end;
procedure TThemconnectDialogFrm.SetConnectDialog(Value: TMyConnectDialog);
begin
FConnectDialog:= Value;
DoInit;
end;
initialization
if GetClass('TfmMyConnect') = nil then begin
{$IFDEF VER6P}
Classes.StartClassGroup(TfmMyConnect);
{$ENDIF}
Classes.RegisterClass(TThemconnectDialogFrm);
{$IFDEF VER6P}
ActivateClassGroup(TfmMyConnect);
{$ENDIF}
end;
end.
Is this the only way to create an own Connectdialog