asi
asked on
Tlist and numbers (double)
hi
i know that there ispostibility to assigned numbers to Tlist pointer for example if
Value : integer
put(index, TObject(Value))
but if i want to assigned number from type Double , how can i do it ? simple proccess like put(index(Tobject(value( .... give an Error Msg
10x in advance
Asi
i know that there ispostibility to assigned numbers to Tlist pointer for example if
Value : integer
put(index, TObject(Value))
but if i want to assigned number from type Double , how can i do it ? simple proccess like put(index(Tobject(value( .... give an Error Msg
10x in advance
Asi
Yes, with Viktor's solution you can add a reference/pointer to your double values. But the original double variable has to remain valid. That means you can't give in local function variables...
If you don't like that you could use something like this (it's an extract from my delphi help file):
procedure TForm1.FormButton1Click(Se nder: TObject);
type
PMyList = ^AList;
AList = record
I: Integer;
C: Char;
end;
var
MyList: TList;
ARecord: PMyList;
B: Byte;
Y: Word;
begin
MyList := TList.Create;
New(ARecord);
ARecord^.I := 100;
ARecord^.C := 'Z';
MyList.Add(ARecord); {Integer 100 und das Zeichen Z in die Liste einfügen }
New(ARecord);
ARecord^.I := 200;
ARecord^.C := 'X';
MyList.Add(ARecord); {Integer 200 und Zeichen X in die Liste einfügen }
{ Einträge in Paintbox ausgeben )
Y := 10; {Variable für Funktion TextOut }
for B := 0 to (MyList.Count - 1) do
begin
ARecord := MyList.Items[B];
Canvas.TextOut(10, Y, IntToStr(ARecord^.I)); {Display I}
Y := Y + 30; { Y noch einmal inkrementieren }
Canvas.TextOut(10, Y, ARecord^.C); { C ausgeben }
Y := Y + 30; {Y inkrementieren}
end;
{ Aufräumen: Listeneinträge und Liste freigeben }
for B := 0 to (MyList.Count - 1) do
begin
ARecord := MyList.Items[B];
Dispose(ARecord);
end;
MyList.Free;
end;
Regards, Madshi.
If you don't like that you could use something like this (it's an extract from my delphi help file):
procedure TForm1.FormButton1Click(Se
type
PMyList = ^AList;
AList = record
I: Integer;
C: Char;
end;
var
MyList: TList;
ARecord: PMyList;
B: Byte;
Y: Word;
begin
MyList := TList.Create;
New(ARecord);
ARecord^.I := 100;
ARecord^.C := 'Z';
MyList.Add(ARecord); {Integer 100 und das Zeichen Z in die Liste einfügen }
New(ARecord);
ARecord^.I := 200;
ARecord^.C := 'X';
MyList.Add(ARecord); {Integer 200 und Zeichen X in die Liste einfügen }
{ Einträge in Paintbox ausgeben )
Y := 10; {Variable für Funktion TextOut }
for B := 0 to (MyList.Count - 1) do
begin
ARecord := MyList.Items[B];
Canvas.TextOut(10, Y, IntToStr(ARecord^.I)); {Display I}
Y := Y + 30; { Y noch einmal inkrementieren }
Canvas.TextOut(10, Y, ARecord^.C); { C ausgeben }
Y := Y + 30; {Y inkrementieren}
end;
{ Aufräumen: Listeneinträge und Liste freigeben }
for B := 0 to (MyList.Count - 1) do
begin
ARecord := MyList.Items[B];
Dispose(ARecord);
end;
MyList.Free;
end;
Regards, Madshi.
Just remember that TList is for saving pointers...
Cheers,
Viktor
Cheers,
Viktor
ASKER
i know .... the Tlist is for saving pointers but since pointers are 3 bytes they can alos save numbers
integer number is just fine ... and about double .... ?
integer number is just fine ... and about double .... ?
Pointers and integers are 4 byte long, not 3 byte...
Have you looked at my comment???
Have you looked at my comment???
ASKER
Madshi
ya , convert your comment -> answer
and i'll give u the points
Asi
ya , convert your comment -> answer
and i'll give u the points
Asi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is this what you want???