How to put in data

How do i put in data in my members.dat?
I use the sample at

"[italic]Write to a File
Suppose we have filled an array of Delphi members with their names, e-mails and number of posts and we want to store this information in a file on the disk. The following peace of code will do the work:

F : file of TMember;
i : integer;
AssignFile(F,'members.dat') ;
Rewrite(F) ;
for j:= 1 to 50 do
Write (F, Members[j]) ;
CloseFile(F) ;


  • Not really sure what you want cause the same explain everything pretty good.

    The only ammendment I would make to the code is the "Rewrite(F)"

    The reason is Rewrite(F) creates the "members.dat" file on the harddrive, if its already created the data in it will be lost after the next rewrite. The following code will fix that:
    {$I-} {Turns of the Input output error check}
    Reset(F); {Resets the cursor to the first record, if the file does not exists then ioresult's value will be replaced by the error value returned}
    If ioresult <> 0 then {checks whether there was an error with the file reset}
    Rewrtite(F); {creates the file if it doesn't exists}
    {$I+} {Turns back on the input output error checking}

    Further more if you wanted to know which part of the code you have physically puts the data into file its the "write()" procedure.

    Now the only other thing I can now think of might be an issue is to get values to the variables of the record.

    Since the example is using a record array to give a value to the first member's name the code will look like this.

    members[1].name := 'Darkwing Duck';

    Carry on like this filling in all the variables in the record for every array you need...

    Let me know if this little article covered you problem or not.
    Darkwing Duck aka DWduck signing off :)
Sign In or Register to comment.

Howdy, Stranger!

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


In this Discussion