List Info

Thread: type record




type record
country flaguser name
United States
2007-07-29 09:07:41

hi i'm trying to put a record into TStringList.

type
TARecord = record
s: String[5];
end;

var
rec: TARecord;
begin
GetMem(rec, SizeOf(TARecord));
StringList.AddObject('', rec);
end;

my question is, do i have to freemem each record in tstringlist?

thanks in advance

__._,_.___
.

__,_._,___
Re: type record
country flaguser name
United States
2007-07-29 12:04:07

reynaldi81,

>; hi i'm trying to put a record into TStringList.
>
>
>; type
>; TARecord = record
> s: String[5];
> end;
>;
> var
> rec: TARecord;
> begin
> GetMem(rec, SizeOf(TARecord));
> StringList.AddObject('', rec);
> end;
>;
>
> my question is, do i have to freemem each record in tstringlist?

Yes, because TStringList does not know what to do with the TObjects in the
list.

>From your example, you don't seem to use the strings in the string list.
Why don't you just use TObjectList, which has no strings overhead?

Rory Daulton
rorydaulton%40email.com">rorydaultonemail.com

__._,_.___
.

__,_._,___
Re: type record
country flaguser name
United States
2007-07-30 02:00:23

Yes, however...

Use a dynamic array instead if you want to store records. You need to know
how to use them but when you do, they're a lot more practical to use than
stringlists or TLists.

Declaration:
type TARecords = array of TARecord;
var ARecords: TARecords;
var Index: Integer; // For some of the following examples...

Initializing:
SetLength(ARecords, 0);

Freeing all records.
SetLength(ARecords, 0);

Adding record to the end:
Index := Length(ARecords);
SetLength(ARecords, Succ(Index));
ARecords[Index].Field1 := ...;
ARecords[Index].Field2 := ...;
...

Deleting record at position Index:
while (Index < High(ARecords)) do begin
ARecords[Index] := ARecords[Succ(Index)];
Inc(Index);
end;
SetLength(ARecords, Index);

Things become a bit more complicated if you need these records to be sorted,
though.

On 7/29/07, reynaldi81 < reynaldi81%40yahoo.com">reynaldi81yahoo.com> wrote:
&gt;
> hi i'm trying to put a record into TStringList.
>
>
>; type
>; TARecord = record
&gt; s: String[5];
> end;
>;
> var
> rec: TARecord;
> begin
&gt; GetMem(rec, SizeOf(TARecord));
> StringList.AddObject('', rec);
&gt; end;
>;
>
> my question is, do i have to freemem each record in tstringlist?
>
> thanks in advance
>

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )