Ver Mensaje Individual
  #3  
Antiguo 14-05-2007
JF Sebastian JF Sebastian is offline
Miembro
 
Registrado: oct 2006
Posts: 108
Reputación: 18
JF Sebastian Va por buen camino
He intentado hacer un ejemplo de lectura escritura empleando seek pero solo me lee ceros. Ignoro por que.


Código Delphi [-]
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
const max = 1024*1024;
type
  TArr=array[1..max] of double;
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  buf:Tarr;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var  Stream: TFileStream; pos: integer;
begin
  Stream := TFileStream.Create('c:\1.tmp', fmOpenReadWrite);
  try
    for pos := 0 to 512 do
    begin
      Stream.Seek(Pos, soBeginning);
      Stream.ReadBuffer(Buf, SizeOf(Buf));
      Button1.Caption := IntToStr(Trunc(Buf[1]));
      Application.ProcessMessages;
      Stream.Seek(Pos, soBeginning);
      Stream.WriteBuffer(Buf, SizeOf(Buf));
    end;
  finally
    Stream.Free;
  end;
end;
 
procedure TForm1.Button2Click(Sender: TObject);
var  Stream: TFileStream; pos,i: integer;
begin
  Stream := TFileStream.Create('c:\1.tmp', fmCreate);
  try
    for pos := 0 to 512 do
    begin
      fillchar(Buf,sizeof(buf),0);
      for i := 1 to max do Buf[i] := pos;
      Stream.WriteBuffer(Buf, SizeOf(Buf));
      Button2.Caption := IntToStr(Trunc(Buf[1]));
      Application.ProcessMessages;
    end;
  finally
    Stream.Free;
  end;
end;
end.
Responder Con Cita