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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading, writing binary files 1

Status
Not open for further replies.

LucieLastic

Programmer
May 9, 2001
1,694
GB
hi All

Need to read and write text (at the moment) as binary files.

Anyone got some examples, hints or tips?

many thanks
lou
 
There must be a FAQ about text, binary and other files in the pascal Forum

Regards Steven van Els
SAvanEls@cq-link.sr
 
here's a simple example I knocked up
to backup a file. It reads the whole text
file into a binary buffer and writes
it out again.


const
MAXFILESIZE = 10000;

type
TBigBuffer = array[0..MAXFILESIZE] of byte;


procedure DoSomethingWithBuffer( const Buff: TBigBuffer );
begin
// ????
end;

procedure CopyFileAtoB( const NameA, NameB: string );
var
Buffer: TBigBuffer;
SaveSize: integer;
A, B: TFileStream;
begin
FillChar( Buffer, SizeOf(Buffer), 0 );
try
A := TFileStream.Create( NameA, fmOpenRead+
fmShareDenyNone );
A.Position := 0;
A.Read( Buffer, A.Size );
finally
SaveSize := min( A.Size, ;
A.Free;
end;
DoSomethingwithBuffer( Buffer );
try
B := TFileStream.Create( NameB, fmCreate );
B.Position := 0;
B.Write( Buffer, SaveSize );
finally
B.Free;
end;
end;


 
sorry the min statement should read

savesize := min( A.Size, MAXFILESIZE );
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top