Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

save array to file

ok, last problem of my project so far - i'm trying to get this damn array to save to a file, but the file remains blank whatever i change. has anybody got any ideas? thanx in advance.

[code]
procedure TForm1.Save1Click(Sender: TObject);
begin
for j:=1 to 20 do
for i:=1 to 9 do
begin
teacherrecord2.title:=teacherinfo[i].title;
teacherrecord2.surname:=teacherinfo[i].surname;
teacherrecord2.initials:=teacherinfo[i].initials;
teacherrecord2.subject:=teacherinfo[i].subject;
assignfile(tinfo2, 'teacherdata2.dat');
reset(tinfo2);
write (tinfo2, teacherrecord2);
closefile(tinfo2);
end;
end;
[/code]

Comments

  • zibadianzibadian Member Posts: 6,349
    : ok, last problem of my project so far - i'm trying to get this damn array to save to a file, but the file remains blank whatever i change. has anybody got any ideas? thanx in advance.
    :
    : [code]
    : procedure TForm1.Save1Click(Sender: TObject);
    : begin
    : for j:=1 to 20 do
    : for i:=1 to 9 do
    : begin
    : teacherrecord2.title:=teacherinfo[i].title;
    : teacherrecord2.surname:=teacherinfo[i].surname;
    : teacherrecord2.initials:=teacherinfo[i].initials;
    : teacherrecord2.subject:=teacherinfo[i].subject;
    : assignfile(tinfo2, 'teacherdata2.dat');
    : reset(tinfo2);
    : write (tinfo2, teacherrecord2);
    : closefile(tinfo2);
    : end;
    : end;
    : [/code]
    :
    To save data to a file you need to use rewrite() instead of reset(). Also you only save the last record, not the entire array. Here is an example of how of save an array:
    [code]
    procedure TForm1.Save1Click(Sender: TObject);
    begin
    assignfile(tinfo2, 'teacherdata2.dat'); // assign the filename
    rewrite(tinfo2); // (re)create the file
    for i:=1 to 9 do
    write (tinfo2, teacherinfo[i]); // write each element in the array
    closefile(tinfo2); // close the file
    end;
    [/code]
  • Shawn CarterShawn Carter Member Posts: 0

    __ { http://forcoder.org } free ebooks and video tutorials about { Ruby, Scratch, PL/SQL, Go, Python, MATLAB, Java, Delphi, Visual Basic, R, Objective-C, PHP, Assembly, C, Swift, C#, C++, Visual Basic .NET, Perl, JavaScript FoxPro, Awk, Scheme, Ada, Crystal, Rust, SAS, ML, Lua, Apex, F#, Bash, Prolog, Scala, Lisp, COBOL, ABAP, LabVIEW, Transact-SQL, D, Erlang, Alice, VBScript, Fortran, Dart, Logo, Julia, Kotlin, Hack, Clojure } ______

Sign In or Register to comment.