Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Untyped Binary Files (https://www.delphipraxis.net/63488-untyped-binary-files.html)

sk.Silvia 21. Feb 2006 19:20

Re: Untyped Binary Files
 
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var MFile:file;
    var i1,tmp:integer;
  begin
  randomize;
  AssignFile(MFile,'cisla.bin');
  rewrite(MFile,1);
  for i1:=1 to 25 do
    begin
    tmp:=random(500);
    BlockWrite(MFile,tmp,SizeOf(Integer));
    Memo1.Lines.Append(IntToStr(tmp));
    end;
  //CloseFile(MFile);
  reset(MFile,1);
  while not eof(MFile) do
    begin
    BlockRead(MFile,tmp,SizeOf(Integer));
    Memo2.Lines.Append(IntToStr(tmp));
    end;

  CloseFile(MFile);
  end;

procedure TForm1.Button3Click(Sender: TObject);
var MFile:File;
    tmp:integer;
  begin
  AssignFile(MFile,'cisla.bin');
 
  reset(MFile,1);
  //showmessage('1');
  while not(eof(MFile)) do
    begin
    //showmessage('2');
    BlockRead(MFile,tmp,SizeOf(Integer));
    //showmessage('3');
    Memo3.Lines.Append(IntToStr(tmp));
    //showmessage('4');
    end;

  closefile(MFile);
  end;

thank you marabu, this finaly worked:) but iam not geting it why i had to use the 1 in reset(MFile,1); and rewrite(); and also why was the first read successfull and the 2 one failed failed?

Daniel G 21. Feb 2006 20:14

Re: Untyped Binary Files
 
Zitat:

Zitat von sk.Silvia
but iam not geting it why i had to use the 1 in reset(MFile,1); and rewrite();

'Cause you are working with untyped files. :zwinker:

I don't really now how it works, but the Delphi help says...ehm...damn, i've got the german version. So no quotation. :wink:

The help says that "only a blocksize of 1 will almost every time lead to a correct size." And I guess that this has also to do with the size of your buffer you are using in

Delphi-Quellcode:
BlockRead(MFile,tmp,1);
because this is also 1.


So long,
Daniel


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:55 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz