Article View: comp.lang.pascal.delphi.misc
Article #308Re: file of record with dynamic array
From: Shay
Date: Wed, 25 Jul 2001 13:55
Date: Wed, 25 Jul 2001 13:55
71 lines
3620 bytes
3620 bytes
Thank you very much. shay. "Andy" <agribanov@paradise.net.nz> wrote in message news:<vI377.211$ww1.12339@news02.tsnz.net>... > 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:
<d44d2b3f.0107250555.e4e0411@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!postnews1.google.com!not-for-mailReferences:
<d44d2b3f.0107230743.1051539d@posting.google.com> <vI377.211$ww1.12339@news02.tsnz.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10baee,15a075613f62d61c X-Google-Attributes: gid10baee,public X-Google-Thread: 1043cf,15a075613f62d61c X-Google-Attributes: gid1043cf,public X-Google-Thread: fd817,15a075613f62d61c X-Google-Attributes: gidfd817,public X-Google-ArrivalTime: 2001-07-25 06:55:12 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.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: Re: file of record with dynamic array Date: 25 Jul 2001 06:55:12 -0700 Organization: http://groups.google.com/ Lines: 71 Message-ID: <d44d2b3f.0107250555.e4e0411@posting.google.com> References: <d44d2b3f.0107230743.1051539d@posting.google.com> <vI377.211$ww1.12339@news02.tsnz.net> NNTP-Posting-Host: 213.8.151.253 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 996069312 1984 127.0.0.1 (25 Jul 2001 13:55:12 GMT) X-Complaints-To: groups-support@google.com NNTP-Posting-Date: 25 Jul 2001 13:55:12 GMT