Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write/Read data from file

Status
Not open for further replies.

jgd12345

Technical User
Apr 22, 2003
124
GB
Hi, I'm working on a project at college and I need some way of storing some data for customer records.

I've looked into types of database but I think it would be easier if I stored it via files. I looked on the delphi help and found the following for writing to files, but don't know how to use it. I would be greatful if someone could give me an example, aswell as an example of how to load from the file to put the data back into an array.

I would be greatful for your help. Thanx

procedure SaveToFile(const FileName: string = ''; Format TDataPacketFormat=dfBinary);
 
Remember, string variables can hold binary data.
Code:
with TFileStream.Create(AFileName, fmCreate) do
try
   Write(PChar(DataString)^ Length(DataString));
finally
   Free;
end;
[\code]
and
[code]
with TFileStream.Create(AFileName, fmOpenRead) do
try
   SetLength(FileData, Size);
   Read(PChar(FileData)^, Size);
finally
   Free;
end;
[\code]

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top