![]() |
![]() |
#1 (permalink) |
"Officer, I was in fear for my life"
Location: Oklahoma City
|
[Delphi] Help with binary files
First of all, don't laugh because I'm using Delphi...it's not my choice.
I have to rewrite a c program in delphi and I'm having trouble dealing with binary files. Here is my c code: Code:
FILE:*fp,*fp1; int:i,j; fp=fopen(binfile,"rb"); while (!feof(f2)) { fp1=fopen(temp,"wb"); for(i=0;i<100000;i++) { ch=fgetc(fp); if(feof(fp)) { break; } fputc(ch,fp1); } fclose(fp1); do something with temp } I need to do the same thing but only in Delphi. |
![]() |
![]() |
#2 (permalink) |
Upright
|
There is nothing wrong with Delphi it is a very good language. Most people just don't know about it and think it sucks. Those same people like VB.
Look at the FFileStream class it should do what you want. And fast to because you are not doing it byte by byte, it uses buffers instead. |
![]() |
![]() |
#3 (permalink) |
"Officer, I was in fear for my life"
Location: Oklahoma City
|
I finally figured out how to do this with block read and block write. Looks something like this:
Code:
var f1,f2:file; cnt:integer; assignfile(f1,infile); reset(f1,100000); while not eof(f1) do begin blockread(f1,ch,1,cnt); assignfile(f2,outfile); rewrite(outfile,100000); blockwrite(f2,ch,cnt); end; |
![]() |
Tags |
binary, delphi, files |
|
|