Own logindialog will not work

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jkuiper
Posts: 138
Joined: Fri 04 Aug 2006 14:17

Own logindialog will not work

Post by jkuiper » 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

Code: Select all

  MyConnection1.ConnectDialog.DialogClass := 'TThemconnectDialogFrm';
This is my dialog:

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.
I can't see what I'm doing wrong.

Is this the only way to create an own Connectdialog :?:

Challenger
Devart Team
Posts: 925
Joined: Thu 17 Nov 2005 10:53

Post by Challenger » Thu 16 Oct 2008 07:45

Please check that code in the initialization section of the ThemConnectDialog module is executed.

jkuiper
Posts: 138
Joined: Fri 04 Aug 2006 14:17

Post by jkuiper » Thu 16 Oct 2008 14:35

Please, tell me more. What do you mean by executing ThemConnectDialog?

Challenger
Devart Team
Posts: 925
Joined: Thu 17 Nov 2005 10:53

Post by Challenger » Fri 17 Oct 2008 10:39

I ment code in initialization section. Please put breakpoint on the

Code: Select all

Classes.RegisterClass(TThemconnectDialogFrm); 
line and run application in debug mode.

[/code]

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 29 Oct 2008 10:30

Thank you for the information. The problem is that MyConnection1 has not assigned ConnectDialog. To solve the problem you should add the following code:

Code: Select all

MyConnection1.ConnectDialog := MyConnectDialog1;
before the line:

Code: Select all

MyConnection1.ConnectDialog.DialogClass := 'TThemconnectDialogFrm';

jkuiper
Posts: 138
Joined: Fri 04 Aug 2006 14:17

Post by jkuiper » Wed 29 Oct 2008 13:17

Thanks, it works :D

Post Reply