question about pointers
Posted on 2001-08-23
Suppose I have a record like such:
pMsgRec = ^msgRec;
msgRec = record
msgID:array [0..23] of char;
Now suppose I have a TList that I want to add msgRec to.
Lets say in a program I assign some values to msg:
messages : TStringList;
for i:= 0 to 4 do
New(msg); //Do I need to do this?
msg.msgType := 'NEW';
Dispose(msg); //Do I need this?
Now lets say I want to get a message back out
for i:= 0 to messages.count-1 do
msg := messages.item(i);
//do some work
msg := nil; // Do I need this?
I'm confused on
1. after insertion into the tlist I have a list of pointers. Where does the actual record exist? (I assume it exists since I used New()).
2. If I dispose(msg) does the item placed in the list no longer point to a memory location? Or if I'm not suppose to dispose(msg), does the next iteration through the loop assign it to another record and the previous one is lost?
3. When reading it out do I need to set it to nil before getting the next record out of the list?
4. Why use pointers at all. Can't I just fill the TList with records?