Y
yufandi
Unregistered / Unconfirmed
GUEST, unregistred user!
大家请看我这个程序,我想实现各种进制的转换,编译可以通过,
但程序执行时出错。能帮我解决问题并能帮我解释清楚的话,绝对
不吝啬分数。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms,
dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
Label4: TLabel;
Edit4: TEdit;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
private
function convertnum(value: string):string;
function Ex(Bs,x:real):extended;
function Alinger(Ss: string):string;
{ Private declarations }
public
end;
var
Form1: TForm1;
implementation
var
NumInSys,NumOutSys:integer;
NumIn,NumOut:string;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
NumIn:=edit1.text;
NumInSys:=strtoint(edit2.text);
NumOutSys:=strtoint(edit4.text);
NumOut:=convertnum(NumIn);
edit2.text:=NumOut;
end;
function TForm1.convertnum(value: string):string;
var
n2:string;
nc:char;
i,n,k,m:int64;
v:comp;
begin
n:=0;
i:=length(value);
k:=0;
v:=0;
repeat
nc:=value;
nc:=upcase(nc);
if ((nc>='0') and (nc<='9')) then
begin
n:=ord(nc);
n:=n-48;
end
else
if ((nc>='A') and (nc<='Z')) then
begin
n:=ord(nc);
n:=n-55;
end;
{$Q+}
try
v:=v+(n*round(Ex(NumInSys,k)));
except
showmessage('overflow');
i:=-1;
end;
{$Q+}
i:=i-1;
k:=k+1;
until i<1;
n2:=''; i:=60;
repeat m:=trunc(v) mod NumOutSys;
v:=trunc(v)/NumOutSys;
if ((m>=0) and (m<=9)) then
begin
n2:=chr(m+48);
i:=i-1;
end
else begin
m:=m-9;
n:=64;
n:=n+m;
n2:=chr();
i:=i-1;
end;
until v<=0;
result:=alinger(n2);
end;
function Tform1.Ex(Bs,x:real):extended;
var
a,k:extended;
begin
a:=Bs;
k:=x;
Result:=exp(ln(a)*k);
end;
function TForm1.Alinger(Ss:string):string;
var
i,j:integer; v:string;
begin
v:='';
i:=1;
j:=1;
repeat
if ss=' '
then
i:=i+1
else
begin
v[j]:=ss;
j:=j+1;
i:=i+1;
end;
until i>length(ss);
Result:=v;
end;
end.
但程序执行时出错。能帮我解决问题并能帮我解释清楚的话,绝对
不吝啬分数。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms,
dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
Label4: TLabel;
Edit4: TEdit;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
private
function convertnum(value: string):string;
function Ex(Bs,x:real):extended;
function Alinger(Ss: string):string;
{ Private declarations }
public
end;
var
Form1: TForm1;
implementation
var
NumInSys,NumOutSys:integer;
NumIn,NumOut:string;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
NumIn:=edit1.text;
NumInSys:=strtoint(edit2.text);
NumOutSys:=strtoint(edit4.text);
NumOut:=convertnum(NumIn);
edit2.text:=NumOut;
end;
function TForm1.convertnum(value: string):string;
var
n2:string;
nc:char;
i,n,k,m:int64;
v:comp;
begin
n:=0;
i:=length(value);
k:=0;
v:=0;
repeat
nc:=value;
nc:=upcase(nc);
if ((nc>='0') and (nc<='9')) then
begin
n:=ord(nc);
n:=n-48;
end
else
if ((nc>='A') and (nc<='Z')) then
begin
n:=ord(nc);
n:=n-55;
end;
{$Q+}
try
v:=v+(n*round(Ex(NumInSys,k)));
except
showmessage('overflow');
i:=-1;
end;
{$Q+}
i:=i-1;
k:=k+1;
until i<1;
n2:=''; i:=60;
repeat m:=trunc(v) mod NumOutSys;
v:=trunc(v)/NumOutSys;
if ((m>=0) and (m<=9)) then
begin
n2:=chr(m+48);
i:=i-1;
end
else begin
m:=m-9;
n:=64;
n:=n+m;
n2:=chr();
i:=i-1;
end;
until v<=0;
result:=alinger(n2);
end;
function Tform1.Ex(Bs,x:real):extended;
var
a,k:extended;
begin
a:=Bs;
k:=x;
Result:=exp(ln(a)*k);
end;
function TForm1.Alinger(Ss:string):string;
var
i,j:integer; v:string;
begin
v:='';
i:=1;
j:=1;
repeat
if ss=' '
then
i:=i+1
else
begin
v[j]:=ss;
j:=j+1;
i:=i+1;
end;
until i>length(ss);
Result:=v;
end;
end.