Jump to content
David Schwartz

A Curious Inheritance Problem... what pattern solves it?

Recommended Posts

Is it bad to use official DLL ? Several questions:

* are you limited in distributing capabilities of this DLL (license, space, what ever) ?

* who will support you, when something is broken, and you are using non-official connectivity ?

* with whom you you can discuss your connectivity problems on INet, if you are using some from 3d party ?

* how long will live your software, when 3d party provider is out of business, and DLL "insides"/protocol are changed ?

 

Share this post


Link to post
27 minutes ago, Dmitry Arefiev said:

Is it bad to use official DLL ? Several questions:

* are you limited in distributing capabilities of this DLL (license, space, what ever) ?

* who will support you, when something is broken, and you are using non-official connectivity ?

* with whom you you can discuss your connectivity problems on INet, if you are using some from 3d party ?

* how long will live your software, when 3d party provider is out of business, and DLL "insides"/protocol are changed ?

 

It wasn't my choice, and I personally don't care. It's just what I've been given to work with.

 

Upper Management makes all sorts of decisions regardless of my input, for reasons that are opaque to me, and I've learned it's safer to just accept their decisions.

Edited by David Schwartz

Share this post


Link to post

The above given approach with Generics is really exciting and exactly that what I'm searching for. I tried to adjust that to me needs, however I'm stuck at the very beginning as I run into a compile error with the given syntax "E2003 undeclared identifier TxQuery".

Anybody knows how is the exact "class of" syntax in conjunction with Generics? Couldn't find anything in Delphi's docu.

type
  TxQuery<T: TDataSet> = class abstract
   private
     FiQuery: T;
   protected
     function GetSQL: TStrings; virtual; abstract;
     function GetDataSet: TDataSet; virtual; abstract;
     property iQuery: T read FiQuery write FiQuery;
   public
     procedure Execute; virtual; abstract;
     property SQL: TStrings read GetSQL;
     property DataSet: TDataSet read GetDataSet;
  end;
  TxQueryClass = class of TxQuery; --> compile error

Share this post


Link to post

There is no data type TxQuery it's TxQuery<T: TDataset>. Unfortunately in Delphi you cannot have a class reference to a generic class. I've even tried this:

 

type

  TFDxQuery = TxQuery<TFDQuery>;

  TxFDQueryClass = class of TFDxQuery ;
 

an it also fails with [dcc32 Error] Unit1.pas(43): E2021 Class type required I would expect that TFDxQuery is a class.

Share this post


Link to post

My workaround for generic classes is a non-generic base class.

 

The challenge is always how to wrap stuff in such a way that you can get done what you need get done with the methods and properties defined in the abstract base class.

I.e. Keep the T stuff out of the methods as far as possible.

 

Rough example...

type
  TxQuery = class abstract
   protected
     function GetSQL: TStrings; virtual; abstract;
     function GetDataSet: TDataSet; virtual; abstract;
   public
     constructor Create; virtual; // doesn't really need to do anything but exist
     procedure Execute; virtual; abstract;
     property SQL: TStrings read GetSQL;
     property DataSet: TDataSet read GetDataSet;
  end;

  TxQuery<T: TFDDataSet> = class(TxQuery)
   private
     FiQuery: T;
   protected
     // overrides
     property iQuery: T read FiQuery write FiQuery;
   public
     // overrides
     constructor Create; override; // initialize the T stuff
  end;

  TxQueryClass = class of TxQuery;

 

  • Like 3

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×