some questions about records in Delphi:
TList<T>
), are there need to use pointer yet? if not, how to delete/release each record into a Generic Container? If I wanna delete a specific record into a Generic Container, how to do it?For 1 and 2: records are value types, while classes are reference types. They're allocated on the stack, or directly in the memory space of any larger variable that contains them, instead of through a pointer, and automatically cleaned up by the compiler when they go out of scope.
As for your third question, a TList<TMyRecord>
internally declares an array of TMyRecord
for storage space. All the records in it will be cleaned up when the list is destroyed. If you want to delete a specific one, use the Delete
method to delete by index, or the Remove
method to find and delete. But be aware that since it's a value type, everything you do will be making copies of the record, not copying references to it.