2010/5/7 spir ☣ <denis.s...@gmail.com>:
> I cannot directly "fish" and use the pointer's target. Seems I always need to 
> pass _via_ the pointer, then all is fine. It's not really annoying. But I 
> don't understand the difference: in code, both versions are indeed strictly 
> equivalent. I guess there's an implicit (pointer?) conversion somewhere?
> Are there cases where the pointer's mediation is not needed?

There is an implicit conversion when you assign p := l[0], which is
PInteger := Pointer.

TFPList uses untyped Pointer for storage. You would need to make a
descendant class of TFPList and change methods to use PInteger (at
least for Items property and Get, Put methods). Then use this new
class specialized for storing PIntegers instead of TFPList.

Or take a look at generics in FPC. There is a generic class TFPGList
defined in unit "fgl". Use it like this:

uses
   fgl;
type
   TPIntegerList = specialize TFPGList<PInteger>;
var
       l : TPIntegerList;
       i : Integer;
       p : ^Integer;
begin
       l := TPIntegerList.Create;
       i := 1 ; new(p) ; p^ := i; l.Add(p);
       p := l[0] ; writeln(p^);
       writeln(l[0]^);                 // no error
end.

--
cobines
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to