Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Ayuda con archivos binarios usando TFileStream (https://www.clubdelphi.com/foros/showthread.php?t=83295)

Eze32 31-05-2013 16:41:54

Ayuda con archivos binarios usando TFileStream
 
Hola Necesito hacer el un porgrama donde guarde en un archivo binario mediante TFileStream la posicion en donde esta quedo por ultimas ves la ventana, y el ancho y largo de la misma, pero al codificarlo me da el siguiente error:

[Pascal Error] Ejercicio3.pas(41): E2036 Variable required
[Pascal Error] Ejercicio3.pas(42): E2036 Variable required
[Pascal Error] Ejercicio3.pas(65): E2197 Constant object cannot be passed as var parameter
[Pascal Error] Ejercicio3.pas(66): E2197 Constant object cannot be passed as var parameter
[Pascal Error] Ejercicio3.pas(67): E2197 Constant object cannot be passed as var parameter
[Pascal Error] Ejercicio3.pas(68): E2197 Constant object cannot be passed as var parameter
[Pascal Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Ejercicio3.pas'

Les agradeceria mucho si me dicen como hacer para usar bien archivos binarios en este programa.Muchas Gracias

El codigo es el siguiente:

Código:


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
  Ini : TiniFile;
  Binario : TFileStream;
begin
  //Con Archivo Ini
  // Ini := TiniFile.Create(ExtractFilePath(Application.ExeName) + 'Config.ini');
  //Ini.WriteInteger('DIMESION','Ancho',Width);
  //Ini.WriteInteger('DIMESION','Alto',Height);
  //Ini.WriteInteger('Posicion','Izquierdo',Left);
  //Ini.WriteInteger('Posicion','Superior',top);
  //Ini.free;

  //Con Archivo Binario
  Binario := TFileStream.Create(ExtractFilePath(Application.ExeName) + 'Config.dat',fmCreate);
  Binario.Write(Left,sizeof(integer));
  Binario.Write(Top,sizeof(integer));
  Binario.Write(Width,sizeof(integer));
  Binario.Write(Height,sizeof(integer));
  Binario.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Ini : TiniFile;
  Binario : TFileStream;
begin
  //Con Archivo Ini
  //Ini := TiniFile.Create(ExtractFilePath(Application.ExeName) + 'Config.ini');
  //Width := Ini.ReadInteger('DIMESION','Ancho',0);
  //Height := Ini.ReadInteger('DIMESION','Alto',0);
  //Left := Ini.ReadInteger('Posicion','Izquierdo',0);
  //Top := Ini.ReadInteger('Posicion','Superior',0);
  //Ini.free;

  //Con Archivo Binario
  Binario := TFileStream.Create(ExtractFilePath(Application.ExeName) + 'Config.dat',fmOpenRead);
  while Binario.Position < Binario.Size do
  begin
  Left := Binario.Read(Left ,sizeof(integer));
  Top := Binario.Read(Top ,sizeof(integer));
  Width :=Binario.Read(Width ,sizeof(integer));
  Height := Binario.Read(Height ,sizeof(integer));
  end;

  Binario.Free;
end;


ecfisa 31-05-2013 17:16:58

Hola Eze32 , bienvenido a Club Delphi :)

Como a todos los ingresan te invitamos a que leas nuestra guía de estilo.

Código Delphi [-]
...
procedure TForm1.FormCreate(Sender: TObject);
var
  l,t,w,h: Integer;
begin
  with TFileStream.Create(ExtractFilePath(Application.ExeName)+'Config.dat', fmOpenRead) do
  try
    Seek(0, soFromBeginning);
    Read(l, SizeOf(integer));
    Read(t, SizeOf(integer));
    Read(w, SizeOf(integer));
    Read(h, SizeOf(integer));
    Left   := l;
    Top    := t;
    Width  := w;
    Height := h
  finally
    Free
  end;
end;

...

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  with TFileStream.Create(ExtractFilePath(Application.ExeName)+'Config.dat', fmCreate) do
  try
    Write(Left, SizeOf(integer));
    Write(Top, SizeOf(integer));
    Write(Width, SizeOf(integer));
    Write(Height, SizeOf(integer))
  finally
    Free
  end;
end;

...

Saludos. :)

Edito: ¿ No te resulta mas sencillo hacerlo con el registro de windows ?

Eze32 04-06-2013 16:18:07

Gracias por la respuesta me sirvio mucho la ayuda. :D


La franja horaria es GMT +2. Ahora son las 06:33:33.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi