[Lazarus] How to cast a Interface to a Object in Lazaeus

Michael Van Canneyt michael at freepascal.org
Fri Mar 13 11:34:09 CET 2015



On Fri, 13 Mar 2015, Martin Schreiber wrote:

> On Friday 13 March 2015 11:06:19 Michael Van Canneyt wrote:
>> On Fri, 13 Mar 2015, Martin Schreiber wrote:
>>> On Friday 13 March 2015 10:49:43 aradeonas wrote:
>>>> OK,So in the end how can I cast a Interface to a Object in Lazarus?
>>>
>>> I usually add a "function getinstance(): <theBaseImplemetationClass>" to
>>> the interface definition.
>>
>> Which goes completely against the very purpose of interfaces.
>>
>> If you need this, you should not be using interfaces to begin with.
>>
>> The only possible excuse is an external requirement to use interfaces.
>>
> I do not agree.

No surprise there, I assume you would not have done it otherwise.
It is a free world, after all.

I consider that very wrong design, and this is the reason the OP had to wait 
for his answer so long; I tried to provide alternatives for what is in my 
personal opinion a unnecessarily complicated and convoluted design.

The fact that no-one else bothered to (or could) reply is IMHO enough of a 
hint that the design is maybe not optimal ?

Michael.




More information about the Lazarus mailing list