Posted by William
In Reply to: Create()-probs posted by Martin Knappe var ... P: Pointer; Entry: TEntry; begin P := nil; ... while ... Entry := TEntry.Create(); if P = Addr(Entry) then ShowMessage('Same address!!!'); ... Self.Add(Addr(Entry)); P := Addr(entry); end; ... end; : [...] always get the 'Same address!!!' message. This is not what I intend. I
obviously intend to create [...] objects and have them all added to my list. You are not comparing the POINTERS that you receive from Create(), but you are comparing ADDR(Entry)
and of course that is always the same. var ... Entry, PreviousEntry: TEntry; begin PreviousEntry := nil; while ... Entry := TEntry.Create(); if Entry = PreviousEntry then ShowMessage('Same object!); Self.Add(Entry); PreviousEntry := Entry; ... end; ... end; DelphiLand Discussion Forum |