Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   File of Byte (https://www.clubdelphi.com/foros/showthread.php?t=68140)

kdemia 27-05-2010 03:37:43

File of Byte
 
que tal.. miren mi problema es el siguiente.. yo lo que quiero es teniendo un codigo hexa en un TEdit pasarlo de alguna manera a byte y hacer un write sobre el archivo

procedure TForm1.FormCreate(Sender: TObject);
var
arc: file of byte;
i: Integer;
begin
AssignFile(arc, 'a.txt');
rewrite(arc);
for i := 1 to Length(Edit1.Text) do
begin
case Edit1.Text[i] of
'1'..'9': write(arc, IntToHex(StrToInt(Edit1.Text[i])));
'A': write(arc, IntToHex(10));
'B': write(arc, IntToHex(11));
'C': write(arc, IntToHex(12));
'D': write(arc, IntToHex(13));
'E': write(arc, IntToHex(14));
'F': write(arc, IntToHex(15));
end;
end;
end;


Esto es lo que tengo.. probe directamente copiando de internet algunos StrToHex y nada.. igualmente me dije en SysUtils y IntToHex devuelve un string asi q no se.. tmb probe con esto:

procedure TForm1.FormCreate(Sender: TObject);
var
arc: file of byte;
i: Integer;
begin
AssignFile(arc, 'a.txt');
rewrite(arc);
for i := 1 to Length(Edit1.Text) do
begin
case Edit1.Text[i] of
'1': write(arc, $1);
'2': write(arc, $2);
'3': write(arc, $3);
'4': write(arc, $4);
'5': write(arc, $5);
'6': write(arc, $6);
'7': write(arc, $7);
'8': write(arc, $8);
'9': write(arc, $9);
'A': write(arc, $A);
'B': write(arc, $B);
'C': write(arc, $C);
'D': write(arc, $D);
'E': write(arc, $E);
'F': write(arc, $F);
end;
end;
end;

y tmp che a ver si alguien me da una manopla XD

Ñuño Martínez 27-05-2010 10:26:48

Si es que buscáis siempre lo difícil. :rolleyes:

Lo que tienes que usar es StrToInt. Por ejemplo:

Código Delphi [-]
FUNCTION ConvertirValor (ValorHex: STRING): BYTE;
BEGIN
  RESULT := BYTE (StrToInt (ValorHex) AND $000000FF);
END;

VAR
  Valor: BYTE;
BEGIN
  Valor := ConvertirValor ('$A1');
END;

El "AND" sirve para maneter el valor en 8bit y evitar el desbordamiento.

kdemia 27-05-2010 19:21:36

gracias ñuño en verdad me sirvio mucho.. mil gracias


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

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