Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Ayuda con procedimientos (https://www.clubdelphi.com/foros/showthread.php?t=4739)

RedVenom 25-10-2003 23:22:58

Ayuda con procedimientos
 
Estoy haciendo un programa para con vertir numeros de hexadecimal a decimal y estoy haciendo lo siguiente:

implementation
{$R *.dfm}
function BaseNADec(num : string; n : byte) : integer;
var
i : integer;
aux : string;
begin
// Solo hasta la 'o' = como máximo base 20... suficiente ¿no?
aux:='0123456789ABCDEF';
result:=0;
for i:=1 to length(num) do result:=result*n+pos(upcase(num[i]),aux)-1;
end;

// De base 16 (hexadecimal) a base 10 (decimal)
function HexADec(num : string) : integer;
begin
result:=BaseNADec(num,16);
end;



procedure TForm1.Button1Click(Sender: TObject);
var
x : integer;
v : string;
begin
x:=256;
v := HexADec(x);
edit2.Text := v;
end;

end.


Pero no lo puedo ejecutar porque me dice que son inconpatible integer con string ayudenme por favor a encontrar el error por favor ya que soy novato en esto.

Gracias.

marcoszorrilla 25-10-2003 23:33:41

Código:

procedure TForm1.Button1Click(Sender: TObject);
var
x : integer;
v : string;
begin
x:=256;
v := IntToStr(HexADec(x));
edit2.Text := v;
end;

El problema es que declaras V como String y le quieres asignar un número entero.

Un Saludo.

marcoszorrilla 25-10-2003 23:50:06

Aquí tienes un truco para pasar un número de Hexadecimal a Decimal.

Código:

procedure TForm1.Button1Click(Sender: TObject);
Var
MiHexa:String;
Hexa2Dec:Integer;
begin
MiHexa:='FFFF';
Hexa2Dec:= StrToInt( '$'+MiHexa);
ShowMessage(IntToStr(Hexa2Dec));
end;

Un Saludo.

RedVenom 26-10-2003 02:36:20

hice las siguientes modificaiones al codigo:

[color=red]implementation
{$R *.dfm}
function BaseNADec(num : string; n : byte) : integer;
var
i : integer;
aux : string;
begin
// Solo hasta la 'o' = como máximo base 20... suficiente ¿no?
aux:='0123456789ABCDEF';
result:=0;
for i:=1 to length(num) do result:=result*n+pos(upcase(num[i]),aux)-1;
end;

// De base 16 (hexadecimal) a base 10 (decimal)
function HexADec(num : string) : integer;
begin
result:=BaseNADec(num,16);
end;

// De base 2 (binario) a base 10 (decimal)
function BinADec(num : string) : integer;
begin
result:=BaseNADec(num,2);
end;

// De base 8 (octal) a base 10 (decimal)
function OctADec(num : string) : integer;
begin
result:=BaseNADec(num,8);
end;



procedure TForm1.Button1Click(Sender: TObject);
Var
M:String;
HexADec,BinADec,OctADec:Integer;
begin
if combobox1.Text:= 'Binario' and combobox2.Text:= 'Decimal' then
begin
M:=edit1.text;
BinADec:= StrToInt( '$'+M);
edit2.Text:= IntToStr(BinADec);
else
begin
if combobox1.Text:= 'Hexadecimal' and combobox2.Text:= 'Decimal' then
begin
M:=edit1.text;
HexADec:= StrToInt( '$'+M);
edit2.Text:= IntToStr(HexADec);
end; else
begin
if combobox1.Text:= 'Octal' and combobox2.Text:= 'Decimal' then
begin
M:=edit1.text;
OctADec:= StrToInt( '$'+M);
edit2.Text:= IntToStr(OctADec);
end;
end;
end;
end;COLOR]

Pero me da los siguientes errores:
[Error] Unit1.pas(68): Incompatible types: 'String' and 'procedure, untyped pointer or untyped parameter'
[Error] Unit1.pas(73): ';' not allowed before 'ELSE'



No es que quiera abusar de ustedes pero comprendame soy bastante inexperto con esto pero dos o tres indicaciones y ahi solo.
Gracias

Julià T. 26-10-2003 02:01:20

Hola RedVenom:

Los errores que te dan son errores de sintaxis, por ejemplo
Cita:

if combobox1.Text:= 'Binario' and combobox2.Text:= 'Decimal' then
begin
M:=edit1.text;
BinADec:= StrToInt( '$'+M);
edit2.Text:= IntToStr(BinADec);
else
lo correcto seria
Cita:

if (combobox1.Text= 'Binario') and (combobox2.Text= 'Decimal') then
begin
M:=edit1.text;
BinADec:= StrToInt( '$'+M);
edit2.Text:= IntToStr(BinADec)
else
En los condicionales el operador de igualdad es el igual simple '='
Delante de un else nunca puede haber un punto y coma ';'


La franja horaria es GMT +2. Ahora son las 05:55:38.

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