Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Jan : TQueue and record types
| Subject: | TQueue and record types |
| Posted by: | "Craig" (cra..@radicalage.com) |
| Date: | Mon, 15 Jan 2007 16:14:44 |
Hello,
I am having a tough time with the TQueue when dealing with records (or
objects). Here is small code sample:
procedure DoQueue;
var
q:TQueue;
tr : TestRec; //A record type with an integer (.a) and a string (.b)
trp : ^TestRec; //Pointer to TestRec
j : integer;
begin
q := TQueue.Create;
try
tr.a := 12; //Integer
tr.b := 'Hello'; //String
q.Push(@tr);
tr.a := 45; //Integer
tr.b := 'Goodbye'; //String
q.Push(@tr);
//Now get the items in the queue
for j := 0 to q.count - 1 do
begin
trp := q.pop;
ShowMessage(trp.b); //The string, should be first "Hello" then
"Goodbye"
end;
finally
q.free;
end;
end;
This results in "Goodbye" being displayed twice, not "Hello" and "Goodbye".
If I just use integers, not records or objects, everything works as
expected.
Thanks for any help!
Craig