Article View: comp.lang.pascal.delphi.misc
Article #309Re: file of record with dynamic array
From: Andy
Date: Tue, 24 Jul 2001 01:01
Date: Tue, 24 Jul 2001 01:01
67 lines
3485 bytes
3485 bytes
the problem is that the array is not array but a pointer to the array. So for example you can use // write first fields BlockWrite(file,record,integer(@rec.largeStr)-integer(@rec)); // write your string leng := high(rec.largeStr)-low(rec.largeStr)+1 // array size; BlockWrite(file,leng,sizeof(leng)); // you will need it to read BlockWrite(file, largeStr[low(largestr)],leng); // array itself "Shay" <shayt@inter.net.il> wrote in message news:d44d2b3f.0107230743.1051539d@posting.google.com... > 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:
<vI377.211$ww1.12339@news02.tsnz.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!enews.sgi.com!news.xtra.co.nz!newsfeed01.tsnz.net!news02.tsnz.net!not-for-mailReferences:
<d44d2b3f.0107230743.1051539d@posting.google.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fd817,15a075613f62d61c X-Google-Attributes: gidfd817,public X-Google-Thread: 1043cf,15a075613f62d61c X-Google-Attributes: gid1043cf,public X-Google-Thread: 10baee,15a075613f62d61c X-Google-Attributes: gid10baee,public X-Google-ArrivalTime: 2001-07-23 17:57:47 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!enews.sgi.com!news.xtra.co.nz!newsfeed01.tsnz.net!news02.tsnz.net!not-for-mail From: "Andy" <agribanov@paradise.net.nz> Newsgroups: comp.lang.pascal.delphi.misc,alt.comp.lang.borland-delphi,borland.public.delphi.objectpascal References: <d44d2b3f.0107230743.1051539d@posting.google.com> Subject: Re: file of record with dynamic array Lines: 69 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: <vI377.211$ww1.12339@news02.tsnz.net> Date: Tue, 24 Jul 2001 13:01:13 +1200 NNTP-Posting-Host: 202.0.33.145 X-Complaints-To: abuse@tsnz.net X-Trace: news02.tsnz.net 995936155 202.0.33.145 (Tue, 24 Jul 2001 12:55:55 NZST) NNTP-Posting-Date: Tue, 24 Jul 2001 12:55:55 NZST Organization: TelstraSaturn