[fpc-pascal] Is there a way to avoid class casting?
graemeg at opensoft.homeip.net
Tue Jul 28 18:09:30 CEST 2009
Horacio Jamilis wrote:
> Even if I create a descending class for each TLinkedObjectProperty... I
> will not be able to use them...
Could you post the Interface section of your classes and mention what units they are in. Alternatively look at the tiOPF framework and the source code examples. The following website mentions how to get the source code. http://tiopf.sourceforge.net
----------[ tiObject.pas ]---------------------
// you base class of your OPF framework.
TtiObjectList = class(TtiObject)
The following is custom classes in your application.
----------[ customer.pas ]---------------
TCustomerList = class(TtiObjectList)
-----------[ orders.pas ]--------------
TOrderList = class(TtiObjectList)
If you want many-to-many relationships (though you did not mention this in your first posting), then you need to use base classes and to casting. Or pick a "master" class our of the two relationships. The "master" class, lets say TCustomer will contains TOrderList property. But the TOrderList will contain base class and casting. This minimizes casting.
Or use something like the Relationship Manager design pattern. Relationship Manager can also be found in the tiOPF source code:
As another alternative, you can implement relationships using Interfaces. The class definition will only mention the Interface name, not the concrete class type.
> I don´t see a solution... except keeping casting :-(
Like I said, if you can post the interfaces definitions of your classes, it will be easier to see how you use your classes and what solution can be applied. Remember to also mention which class definitions are in which units.
- Graeme -
fpGUI - a cross-platform Free Pascal GUI toolkit
More information about the fpc-pascal