レコードをファイルに書きたい場合は、文字列をansicharの配列として定義することができます。後でそれを文字列のように扱うことができます。
例:
program StrInRecTest;
{$APPTYPE CONSOLE}
uses SysUtils;
type
TStringRec=
packed record
S:array[0..1023] of ansichar;
end;
var
StringRec:TStringRec;
F:File of TStringRec;
begin
StringRec.S := 'Hello';
WriteLn(StringRec.S);
WriteLn('First char is:'+StringRec.S[0]); // watch out with this
// now let's try saving this to a file and reading it back...
// make a long string with x-es
FillChar(StringRec.S,Length(StringRec.S),'X');
StringRec.S[High(StringRec.S)] := #0; // terminate the string
WriteLn(StringRec.S);
// write to a file
AssignFile(F,'tmp.txt');
ReWrite(F);
Write(F,StringRec);
CloseFile(F);
WriteLn;
// read from file
AssignFile(F,'tmp.txt');
Reset(F);
Read(F,StringRec);
CloseFile(F);
WriteLn(StringRec.S); // yay, we've got our long string back
ReadLn;
end.
が私の質問を更新しました。 – Acron