usage of AfterConnect and AfterDisconnect

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
roozgar
Posts: 12
Joined: Thu 24 May 2018 13:05

usage of AfterConnect and AfterDisconnect

Post by roozgar » Wed 29 May 2019 06:41

hello
i have to add a some events to my connection to handle errors and lost connection but dont know how this is possible
my code is like this

Code: Select all

procedure AfterDisConnectMysqlProcess();
begin
   form2.Timer2.Enabled:=false;
   form2.Timer3.Enabled:=false;
end;

procedure AfterConnectMysqlProcess();
begin
   form2.Timer2.Enabled:=true;
   form2.Timer3.Enabled:=true;
end;
...

                UniConnectionRead := TUniConnection.Create(nil);
                UniConnectionRead.ProviderName:='Mysql';
                UniConnectionRead.Server := globalDBIP;
                UniConnectionRead.Username := globalDBUn;
                UniConnectionRead.Password := globalDBPass;
                UniConnectionRead.Database := globalDBName;
                UniConnectionRead.AutoCommit := true;
                UniConnectionRead.SpecificOptions.Values['MySQL.UseUnicode'] := 'True';
                UniConnectionRead.Connected := true;
                UniConnectionRead.AfterConnect := form2.AfterConnectMysqlProcess();
                UniConnectionRead.AfterDisconnect := AfterDisConnectMysqlProcess();
but i got this error

Code: Select all

[dcc32 Error] Unit2.pas(29610): E2010 Incompatible types: 'TNotifyEvent' and 'procedure, untyped pointer or untyped parameter'
how can i resolve this?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: usage of AfterConnect and AfterDisconnect

Post by ViktorV » Thu 30 May 2019 13:28

To solve the issue you can use the next code:

Code: Select all

  TForm2 = class(TForm)
  ...
  public
    procedure AfterDisConnectMysqlProcess(Sender: TObject);
    procedure AfterConnectMysqlProcess(Sender: TObject);
  end;
...
var
  Form2: TForm2;
...
  UniConnectionRead.AfterConnect := Form2.AfterConnectMysqlProcess;
  UniConnectionRead.AfterDisconnect := Form2.AfterDisConnectMysqlProcess;
If this does not help you in solving your issue, please compose a small sample demonstrating the specified behavior and send it to us using the contact form https://devart.com/company/contactform.html, including scripts for creating and filling database objects.

roozgar
Posts: 12
Joined: Thu 24 May 2018 13:05

Re: usage of AfterConnect and AfterDisconnect

Post by roozgar » Sat 01 Jun 2019 05:33

i used your code but i got this error
[dcc32 Error] Unit2.pas(29634): E2010 Incompatible types: 'TNotifyEvent' and 'procedure, untyped pointer or untyped parameter'
it seems it must have a parametr!!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: usage of AfterConnect and AfterDisconnect

Post by ViktorV » Sat 01 Jun 2019 08:11

Please compose a small sample demonstrating the specified behavior and send it to us using the contact form https://devart.com/company/contactform.html

Post Reply