On 07/05/2010 10:29, spir ☣ wrote:
On Fri, 7 May 2010 06:10:30 +0200
cobines <cobi...@gmail.com> wrote:


2010/5/6 spir ☣ <denis.s...@gmail.com>:

(By the way, started playing with TFPList already, and could not find how to 
get data back! I mean the symtric of add(). Even tried indexing (who knows, 
with the syntactic magic of modern language? ;-).)

It is indexing.

var
 l: TFPList;
 p: Pointer;
 index: Integer;
begin
 l := TFPList.Create;
 index := l.Add(p);
 p := l[index];
end;
[...]


Thank you, I must have written a typo or messed up indices, since now it works 
fine. Still, remains a mystery about untyped pointers, illustrated by the code 
below:


Type
  ptInteger = ^Integer;

var
        l : TFPList;
        i : Integer;
        p : ^Integer;
begin
        l := TFPList.Create;
        i := 1 ; new(p) ; p^ := i; l.Add(p);
        p := l[0] ; writeln(p^);
        writeln(l[0]^);                 // error

        writeln(ptInteger(l[0])^);

end.

i.e. cast the untyped pointer into a pointer to integer, so the compiler knows what type of writeln to throw it at.

(untested)

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

Reply via email to