[fpc-pascal] Problem with interfaces

Joao Morais post at joaomorais.com.br
Mon Aug 20 13:35:56 CEST 2007


Darius Blaszijk wrote:
> I've had similar issues some time ago. Have you tried FPC 2.3.1? It has 
> a some interface fixes.

Nope. Trunk, rev. 8290 and still broken :-/

Thanks.

--
Joao Morais



> 
> Joao Morais wrote:
>>
>> Hello,
>>
>> I have the following code:
>>
>> {$mode objfpc}
>> interface
>>
>> ...
>>
>> function DefaultObj: TObject;
>>
>> implementation
>>
>> var
>>   _Holder: IHolder;
>>
>> function DefaultObj: TObject;
>> begin
>>   if not Assigned(_Holder) then
>>     _Holder := THolder.Create(TSomeClass.Create);
>>   Result := _Holder.Instance;
>> end;
>>
>> IHolder is an interface that the THolder class implements. The first 
>> call to the DefaultObj function creates the holder instance, as 
>> expected. New calls to the same function doesn't recreate it. Again, 
>> as expected.
>>
>> The first call that I make to DefaultObj from *another* unit recreate 
>> the object, because, I don't know why, the _holder var points again to 
>> nil.
>>
>> Changing the type of the _holder to THolder (ie an object pointer 
>> instead of an interface pointer) everything works flawlessly.
>>
>> I have tried to create a small sample but couldn't reproduce the 
>> issue, anyway the source of the problem is gpl code. It fails under 
>> 2.0.4 and current fixes_2_2 branch. Hints?
>>
>> Thanks.
>>
>> -- 
>> Joao Morais
>>
>



More information about the fpc-pascal mailing list