Article View: comp.lang.pascal.delphi.misc
Article #310file of record with dynamic array
From: Shay
Date: Mon, 23 Jul 2001 15:43
Date: Mon, 23 Jul 2001 15:43
55 lines
2675 bytes
2675 bytes
hi,
i'm trying to save data (long string with unknown size) to a file.
i need help - i tried to read the posts here about the subject, but i
still don't know what to do.
what i want to do -
save a record to a file , the record has strings (with known size) &
strings (with UNKNOWN size) & integers.
i tried to declared the unknown sized string as "array of char" or
"string" or "^ ArrayOfCharType", but each time i got in the saved file
a pointer to this vaiable, and i want the data of it.
i had to declared the file variable as "file" and not as "file of
EntryType" due to the problem of finalization.
here is an example :
type
EntryType = record
str1 : string[255];
str2 : string[255];
Num1 : integer;
largeStr : array of char;
end;
procedure ...
var
MyFile : file;
MyRec : EntryType ;
sourceStr : string; // a large string that i have from some other
place with unknown size (until i get it)
begin
sourceStr := getSourceString();
SetLength(MyRec.largeStr, length(sourceStr));
// the next line also give me an error, thats why i did a loop
// MyRec.largeStr := sourceStr;
for i := 1 to length(sourceStr) do
begin
MyRec.largeStr[i-1] := Char(sourceStr[i]);
end;
MyRec.str1 := 'line1';
MyRec.str2 := 'line2';
MyRec.num1 := 123record;
AssignFile(MyFile,'data1.dat');
rewrite(MyFile,1);
BlockWrite(MyFile, MyRec, sizeof(MyRec));
closeFile(MyFile);
end;
thanks,
Shay
Technical Details
Message-ID:
<d44d2b3f.0107230743.1051539d@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!postnews1.google.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fd817,15a075613f62d61c,start X-Google-Attributes: gidfd817,public X-Google-Thread: 10baee,15a075613f62d61c,start X-Google-Attributes: gid10baee,public X-Google-Thread: 1043cf,15a075613f62d61c,start X-Google-Attributes: gid1043cf,public X-Google-ArrivalTime: 2001-07-23 08:43:48 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!postnews1.google.com!not-for-mail From: shayt@inter.net.il (Shay) Newsgroups: comp.lang.pascal.delphi.misc,alt.comp.lang.borland-delphi,borland.public.delphi.objectpascal Subject: file of record with dynamic array Date: 23 Jul 2001 08:43:47 -0700 Organization: http://groups.google.com/ Lines: 55 Message-ID: <d44d2b3f.0107230743.1051539d@posting.google.com> NNTP-Posting-Host: 213.8.151.253 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 995903027 8739 127.0.0.1 (23 Jul 2001 15:43:47 GMT) X-Complaints-To: groups-support@google.com NNTP-Posting-Date: 23 Jul 2001 15:43:47 GMT