Board index » delphi » Save and Load Record using RECORD type

Save and Load Record using RECORD type

Well the problem is that I don't know how many records I will store, it's defined at runtime but when I try to use without
  not exists a append method iqual a TextFile

I'will trying to store point (Xi,Yi) and (Xf, Yf) and Color of
Lines to dat file and when I read back I will Draw lines in a Paintbox ....

 

Re:Save and Load Record using RECORD type


Heres a rough idea of what to do...

TMyRecord=record
  Var1: Integer;
  Var2: String;
end;

procedure Save begin
  FileStream.Create
  FileStream.WriteInteger(  <put number of records here> );        // you
said you know at runtime how many records there will be - this is where you
use it
  for 0 to <number of records> do
    FileStream.WriteInteger( CurrentRecord.Var1 );
    FileStream.WriteString( CurrentRecord.Var2 );
  end;
end;

procedure Load
  FileStream.Create
  NumberOfRecords:=FileStream.ReadInteger            // and this is where it
prevents you from overreading the file
  for 0 to NumberOfRecords do
    CurrentRecord.Var1:=FileStream.Readinteger;
    CurrentRecord.Var2:=FileStream.ReadString;
  end;
end;

Quote
"agnaldo" <agna...@tqs.com.br> wrote in message

news:3df8deee$1@newsgroups.borland.com...
Quote

> Well the problem is that I don't know how many records I will store, it's

defined at runtime but when I try to use without
Quote
>   not exists a append method iqual a TextFile

> I'will trying to store point (Xi,Yi) and (Xf, Yf) and Color of
> Lines to dat file and when I read back I will Draw lines in a Paintbox
....

Other Threads