📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
zImage1: TImage;
Label5: TLabel;
Image1: TImage;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
function zhuhuan :integer;
function shitoer:integer;
function shitoba(aa:integer):integer;
function shitoshilu(aa:integer):string;
function ertoshi(aa:string):integer;
function batoer:string;
function shilutoer:string;
public
{ Public declarations }
end;
var
Form1: TForm1;
source:integer;
result:integer;
b,c:integer;
s:integer;
yuan,hou:integer;
d:string;
sbx,sby,sbi,sbj,shubiao:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
d:=edit1.text;
edit2.readonly:=false;
case combobox1.ItemIndex of
0: yuan:=10;
1: yuan:=2;
2: yuan:=8;
3: yuan:=16;
end;
case combobox2.ItemIndex of
0: hou:=10;
1: hou:=2;
2: hou:=8;
3: hou:=16;
end;
b:=length(d);
s:=1;
case yuan of
10: begin
for c:=1 to b do
begin
case d[c] of
'0': s:=0;
'1': s:=0;
'2': s:=0;
'3': s:=0;
'4': s:=0;
'5': s:=0;
'6': s:=0;
'7': s:=0;
'8': s:=0;
'9': s:=0;
else
begin
s:=10;
break;
end;
end;
end;
if s=10 then
messagedlg('输入的数据不属于十进制范围.',mtwarning,[mbok],0)
else
zhuhuan;
end;
2: begin
for c:=1 to b do
begin
case d[c] of
'0': s:=0;
'1': s:=0;
else
begin
s:=2;
break;
end;
end;
end;
if s=2 then
messagedlg('输入的数据不属于二进制范围.',mtwarning,[mbok],0)
else
zhuhuan;
end;
8: begin
for c:=1 to b do
begin
case d[c] of
'0': s:=0;
'1': s:=0;
'2': s:=0;
'3': s:=0;
'4': s:=0;
'5': s:=0;
'6': s:=0;
'7': s:=0;
else
begin
s:=8;
break;
end;
end;
end;
if s=8then
messagedlg('输入的数据不属于八进制范围.',mtwarning,[mbok],0)
else
zhuhuan;
end;
16: begin
for c:=1 to b do
begin
case d[c] of
'0': s:=0;
'1': s:=0;
'2': s:=0;
'3': s:=0;
'4': s:=0;
'5': s:=0;
'6': s:=0;
'7': s:=0;
'8': s:=0;
'9': s:=0;
'a': s:=0;
'A': s:=0;
'b': s:=0;
'B': s:=0;
'c': s:=0;
'C': s:=0;
'd': s:=0;
'D': s:=0;
'e': s:=0;
'E': s:=0;
'f': s:=0;
'F': s:=0;
else
begin
s:=16;
break;
end;
end;
end;
if s=16 then
messagedlg('输入的数据不属于十六进制范围.',mtwarning,[mbok],0)
else
zhuhuan;
end;
end;
result:=0;
end;
function tform1.zhuhuan :integer;
begin
if yuan<>16 then
source:=strtoint(Edit1.text)
else
source:=1;
if yuan=hou then
begin
messagedlg('转换方式相同.',mtwarning,[mbok],0);
combobox2.SetFocus;
end
else
begin
if source=0 then
begin
messagedlg('被转换数为0,请输入正确的值.',mtwarning,[mbok],0);
edit1.SetFocus;
end
else
begin
if (d[1]<>'0') or ((yuan=16) and (d[2]<>'0')) then
begin
if (yuan=10) and (hou=2) then
edit2.text:=inttostr(shitoer);
if (yuan=10) and (hou=8) then
edit2.text:=inttostr(shitoba(shitoer));
if (yuan=10) and (hou=16) then
edit2.text:=shitoshilu(shitoer);
if (yuan=2) and (hou=10) then
edit2.text:=inttostr(ertoshi(edit1.Text));
if (yuan=2) and (hou=8) then
edit2.text:=inttostr(shitoba(strtoint(edit1.text)));
if (yuan=2) and (hou=16) then
begin
source:=ertoshi(edit1.Text);
edit2.text:=shitoshilu(shitoer);
end;
if (yuan=8) and (hou=10) then
edit2.text:=inttostr(ertoshi(batoer));
if (yuan=8) and (hou=2) then
edit2.text:=batoer;
if (yuan=8) and (hou=16) then
edit2.Text:=shitoshilu(strtoint(batoer));
if (yuan=16) and (hou=10) then
edit2.Text:=inttostr(ertoshi(shilutoer));
if (yuan=16) and (hou=2) then
edit2.Text:=shilutoer;
if (yuan=16) and (hou=8) then
edit2.Text:=inttostr(shitoba(strtoint(shilutoer)));
end
else
messagedlg('第一位为0,请输入正确的值.',mtwarning,[mbok],0); ;
end;
end;
edit2.readonly:=true;
end;
function tform1.shitoer:integer;
begin
c:=0;
s:=0;
try
if source=1 then
s:=1
else
begin
while source<>1 do
begin
if c=0 then
c:=1
else
c:=c*10;
b:=source mod 2;
s:=s+b*c;
source:=source div 2;
end;
s:=s+c*10;
end;
except
on econverterror do
messagedlg('数据类型错误'+#13+'请输入正确的值',mtwarning,[mbok],0);
end;
result:=s;
end;
function tform1.shitoba(aa:integer):integer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -