Re: untyped files: record structure

Posted by DelphiMan on January 28, 2006

In Reply to Re: Problem with untyped files (writing to file) posted by Andrew on January 28, 2006

: MyRecord = record
: Name: string[50];
: Desc,
: Code,
: Keys: TStrings;
: End;

: That's the record declaration.

TStrings is an object type. If you store something in Desc, Code or Keys, you store the *pointer* to an object -- just a number, the memory address of the object.

If you want to store *string* values, you have to declare the record fields as "string" with a defined length. For example:

MyRecord = record
Name: string[50];
Desc: string[50];
Code: string[8];
Keys: string[80];
End;

Of course, in that case most of your file will consist of empty space...

A solution: use a *text* file instead of a typed file, where the fields are delimited with separator characters. For example, the CSV format:
"the name", "the description", Code, "key1 key2..."

Related Articles and Replies