Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Leer archivos binarios (https://www.clubdelphi.com/foros/showthread.php?t=83659)

JuanOrtega 11-07-2013 23:57:33

Leer archivos binarios
 
Tengo el siguiente codigo :

Código Delphi [-]
unit test;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    Button3: TButton;
    PerlRegEx1: TPerlRegEx;

    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm} 

procedure TForm1.Button1Click(Sender: TObject);
var
  F: TFileStream;
  Buffer: array [0 .. 1023] of byte;

begin

  F := TFileStream.Create(ExtractFilePath(Application.ExeName)
      + 'test.exe', fmOpenRead);

  while F.Position < F.Size do
  begin

    F.Read(Buffer,1024);

  end;

  F.Free;

end;

El problema esta en que no se como convertirlo a string la variable buffer que es array of bytes para poder buscar ciertos paremetros en la variable string , eh intentado meterlo en un memo pero nada , ¿ alguien tiene alguna idea para ayudarme ?

Todo esto lo eh intentado leyendo este articulo : http://delphiallimite.blogspot.com.a...exto-y_30.html

ecfisa 12-07-2013 01:33:35

Hola Lepuke.

No sé cuál es la finalidad que buscas, pero para pasar el contenido del archivo a un TMemo podes hacer:
Código Delphi [-]
...
var
  Buffer: array [0 .. 1023] of Char;
  str: string;
begin
  Memo1.Clear;
  str := ExtractFilePath(Application.ExeName) + 'test.exe';
  with TFileStream.Create(str, fmOpenRead) do
  try
    Memo1.Lines.BeginUpdate;
    SetLength(str, 1024);
    while Position < Size do
    begin
      Read(Buffer, 1024);
      StrCopy(PChar(str), Buffer);
      Memo1.Lines.Add(str);
    end;
  finally
    Memo1.Lines.EndUpdate;
    Free;
  end;
end;

Saludos :)

JuanOrtega 12-07-2013 01:37:12

gracias , es la solucion correcta , no pudiste ser mas preciso , ¿ que estudiaste para ser programador ?


La franja horaria es GMT +2. Ahora son las 15:13:22.

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