Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > ASM y Microcontroladores
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

 
 
Herramientas Buscar en Tema Desplegado
  #22  
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
Poder: 26
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
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Consulta Delphi 6, Delphi 2005 y Delphi 2006 Leviatan Varios 6 18-08-2007 16:02:08


La franja horaria es GMT +2. Ahora son las 01:21:00.


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
Copyright 1996-2007 Club Delphi