[fpc-pascal] Problem with interfaces

Darius Blaszijk dhkblaszyk at zeelandnet.nl
Mon Aug 20 07:42:00 CEST 2007


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

Darius

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
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>



More information about the fpc-pascal mailing list