在
在世寻欢
Unregistered / Unconfirmed
GUEST, unregistred user!
關於IDE報錯的問題
我編了個三六進制轉換為十進制的小程序:在Edit1中輸入36進制數,按下Button1
則在Edit2中顯示轉換為十進制的結果.可是調試時老是報錯.我的源代碼如下:
Unit unit1
Interface
uses
(這些IDE自動生成,就不贅述了)
Type
TForm1= Class(TForm);
Edit1:TEdit;
Edit2:TEdit;
Button1:TButton;
TRadixSet=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');//指定36進制的基數;
Procedure Button1Click(Sender:TObject);
Procedure Edit1KeyPress(Sender:TObject;Key:Char);//對於使用者的非法基數輸入作處理;
Function RadixConvert(Simbol:TRadixSet;Total,Site:Integer):Int64;//計算某權位上的基數的權值;
Var
Form1:TForm1'
end;
Implementation
Function Step(RadixNumber,Exponent:Integer):Int64;
Var
I:Integer;
MultiBy:Int64;
Begin
If Exponent 0 then
Step:=RadixNumber;
Else
Begin
MultiBy:=1;
For I:=1 To Exponent Do
MultiBy:=MultiBy*36;
Step:=MultiBy*RadixNumber;
End;
Function RadixConvert(Simbol:TRadixSet;Total,Site:Integer):Int64;
Begin
If (Chr(Simbol)>47) and (Chr(Simbol)<58) then
Result:=Step(Chr(Simbol)-48,Toltal-Site);//0到9十個基數對應的十進制數的權值;
Else
Result:=Step(Chr(Simbol)-55,Total-Site);//A到Z 26個基數對應的十進制數的權值;
End;
Procedure TForm1.Button1Click(Sender:TObject);//求出十進制轉換結果並顯示在Edit2中;
Var
J:integer;
Sum:Int64;
Begin
If Edit1.Text='' then MessageDlg('請輸入欲轉換的數據!',mtWarning,〔mbOK〕,0);
Else
Begin
Sum:=0;
For J:=1 to Length(Edit1.Text) do
Sum:=Sum RadixConvert(Edit1.Text1,Length(Edit1.Text),J);
Edit2.Text:=IntToStr(Sum);
End;
End;
Procedure TForm1.Edit1KeyPress(Sender:TObject;Key:Char);
Var
No:Integer;
Begin
No:=Ord(Key);
If not (((No>47) and (No<58)) or ((No>64) and (No<91))) then
Begin
Key:=Chr(0);
Showmessage('非法基數!');
End;
End;
End.
這段代碼調時IDE報錯:Declaration Expected But EndOfFile Found!
而且指針指向最後的End.
還有就是如果先在Type下面申明Step自定義函數,在函數體部分編寫代碼,則RadixConvert函數中不能對其調用.但在Button1Click時間句柄中能調用.這是為什麼?
有誰看出問題來了指點迷津,不勝感激!
我編了個三六進制轉換為十進制的小程序:在Edit1中輸入36進制數,按下Button1
則在Edit2中顯示轉換為十進制的結果.可是調試時老是報錯.我的源代碼如下:
Unit unit1
Interface
uses
(這些IDE自動生成,就不贅述了)
Type
TForm1= Class(TForm);
Edit1:TEdit;
Edit2:TEdit;
Button1:TButton;
TRadixSet=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');//指定36進制的基數;
Procedure Button1Click(Sender:TObject);
Procedure Edit1KeyPress(Sender:TObject;Key:Char);//對於使用者的非法基數輸入作處理;
Function RadixConvert(Simbol:TRadixSet;Total,Site:Integer):Int64;//計算某權位上的基數的權值;
Var
Form1:TForm1'
end;
Implementation
Function Step(RadixNumber,Exponent:Integer):Int64;
Var
I:Integer;
MultiBy:Int64;
Begin
If Exponent 0 then
Step:=RadixNumber;
Else
Begin
MultiBy:=1;
For I:=1 To Exponent Do
MultiBy:=MultiBy*36;
Step:=MultiBy*RadixNumber;
End;
Function RadixConvert(Simbol:TRadixSet;Total,Site:Integer):Int64;
Begin
If (Chr(Simbol)>47) and (Chr(Simbol)<58) then
Result:=Step(Chr(Simbol)-48,Toltal-Site);//0到9十個基數對應的十進制數的權值;
Else
Result:=Step(Chr(Simbol)-55,Total-Site);//A到Z 26個基數對應的十進制數的權值;
End;
Procedure TForm1.Button1Click(Sender:TObject);//求出十進制轉換結果並顯示在Edit2中;
Var
J:integer;
Sum:Int64;
Begin
If Edit1.Text='' then MessageDlg('請輸入欲轉換的數據!',mtWarning,〔mbOK〕,0);
Else
Begin
Sum:=0;
For J:=1 to Length(Edit1.Text) do
Sum:=Sum RadixConvert(Edit1.Text1,Length(Edit1.Text),J);
Edit2.Text:=IntToStr(Sum);
End;
End;
Procedure TForm1.Edit1KeyPress(Sender:TObject;Key:Char);
Var
No:Integer;
Begin
No:=Ord(Key);
If not (((No>47) and (No<58)) or ((No>64) and (No<91))) then
Begin
Key:=Chr(0);
Showmessage('非法基數!');
End;
End;
End.
這段代碼調時IDE報錯:Declaration Expected But EndOfFile Found!
而且指針指向最後的End.
還有就是如果先在Type下面申明Step自定義函數,在函數體部分編寫代碼,則RadixConvert函數中不能對其調用.但在Button1Click時間句柄中能調用.這是為什麼?
有誰看出問題來了指點迷津,不勝感激!