Ver Mensaje Individual
  #24  
Antiguo 23-03-2008
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Creo que no me explique bien, el código no debe escribirse directamente en la unit, se debe encerrar dentro de algún evento como por ejemplo hacer click sobre un botón:
Código Delphi [-]
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  TBuffer = array[$0000..$FFFF] of Byte;

function Insertar(Str: String; var Buffer: TBuffer): String;
var
  i,j,k: Integer;
begin
  Result:= EmptyStr;
  Str:= Trim(Str);
  if Copy(Str,1,1) = ':' then
    if TryStrToInt('$' + Copy(Str,2,2),i) then
      if Length(Str) = ((2*i) + 11) then
        if TryStrToInt('$' + Copy(Str,4,4),j) then
          if TryStrToInt('$' + Copy(Str,8,2),k) then
            if k = 0 then
            begin
              Str:= Copy(Str,10,2*i);
              for k:= j to (j + i - 1) do
              begin
                Buffer[k]:= StrToInt('$' + Copy(Str,1,2));
                Delete(Str,1,2);
              end;
            end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i,j: Integer;
  Str: String;
  Buffer: TBuffer;
begin
  Memo1.Clear;
  with TStringList.Create do
  try
    LoadFromFile('d:\test.hex');
    FillChar(Buffer,Sizeof(Buffer),#0);
    for i:= 0 to Count - 1 do
      Insertar(Strings[i],Buffer);
    Str:= EmptyStr;
    j:= Sizeof(Buffer) - 1;
    while (Buffer[j] = 0) and (j > 0) do
      dec(j);
    for i:= 0 to j do
    begin
      Str:= Str + #32 + IntToHex(Buffer[i],2);
      if ((i+1) mod 16 = 0) then
      begin
        Memo1.Lines.Add(Str);
        Str:= EmptyStr;
      end;
    end;
  finally
    Free;
  end;
end;

end.
Responder Con Cita