Connection not defined by descendant of TmyConnection

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Haust
Posts: 3
Joined: Thu 27 Nov 2008 10:01

Connection not defined by descendant of TmyConnection

Post by Haust » Fri 28 Nov 2008 08:36

In our application we need an extension for each dataset. So we tried to extend the connection component "TMyConnection" in this way:
TMCyConnection = class(TMyConnection)
private
protected
public
User : string;
constructor Create(AOwner:TComponent); override;
destructor destroy; override;
published
end;

TMCyXQuery = class(TMyQuery)
private
FConnection : TMCyConnection;
procedure SetConnection(Connection:TMCyConnection);
protected
public
published
property Connection:TMCyConnection read FConnection write SetConnection;
end;

constructor TMCyConnection.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
User := '???';
end;

procedure TMCyXQuery.SetConnection(Connection:TMCyConnection);
begin
if FConnection Connection then begin
FConnection := Connection;
end;
end;
At runtime the message "Connection is not defined." appears. At designtime setting of the connection to the above dataset type works well, setting of the property "Active" too.

We use Delphi-5 and MyDAC-5.55.0.39.

Where is the fault?

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

Post by jkuiper » Fri 28 Nov 2008 08:46

What I see is logical. When you set a connection to TMCyXQuery, TMCyConnection don't have the connection params to make a connection.

Haust
Posts: 3
Joined: Thu 27 Nov 2008 10:01

Post by Haust » Fri 28 Nov 2008 11:02

How can I solve my problem?

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

Post by Dimon » Mon 01 Dec 2008 07:34

You should use the following code for the TMCyXQuery class:

Code: Select all

TMCyXQuery = class(TMyQuery)
private
  function GetConnection: TMCyConnection;
  procedure SetConnection(Connection: TMCyConnection);
protected
public
published
  property Connection: TMCyConnection read GetConnection write SetConnection;
end;

procedure TMCyXQuery.SetConnection(Connection:TMCyConnection);
begin
  inherited Connection := Connection;
end;

function TMCyXQuery.GetConnection: TMCyConnection;
begin
  Result := TMCyConnection(inherited Connection);
end;

Haust
Posts: 3
Joined: Thu 27 Nov 2008 10:01

Post by Haust » Tue 02 Dec 2008 09:03

Thanks for the useful help. :D

Post Reply