1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| program Numerateur;
uses
Flash8;
{$FRAME_WIDTH 240}
{$FRAME_HEIGHT 160}
{$BACKGROUND $a0a0a0}
type
TEditBox1 = class(TextField)
procedure onKeyDown;
end;
TEditBox2 = class(TextField)
procedure onKeyDown;
end;
TEditBox3 = class(TextField)
procedure onKeyDown;
end;
TEditBox4 = class(TextField)
procedure onKeyDown;
end;
var
e1: TEditBox1;
e2: TEditBox2;
e3: TEditBox3;
e4: TEditBox4;
t1, t2, t3, t4: TextField;
f: TextFormat;
s1, s2, s3, s4: string;
nombre: Integer;
function StrToInt(s: string): Integer;
var
i, tmp, p10: Integer;
begin
tmp := 0;
p10 := 1;
for i := Length(s) downto 1 do
begin
if (Ord(s[i]) >= 48) and (Ord(s[i]) <= 57) then
begin
Inc(tmp, (Ord(s[i]) - 48) * p10);
p10 := p10 * 10;
end;
end;
Result := tmp;
end;
function IntToBase(i, base: Integer): string;
var
digits, tmp: string;
begin
digits := '0123456789ABCDEF';
if i = 0 then
tmp := '0'
else
tmp:='';
while i > 0 do
begin
tmp := digits [i mod base + 1] + tmp;
i := i div base;
end;
result := tmp;
end;
function Position(const c: Char; const s: string): Integer;
var
i, tmp: Integer;
begin
tmp := 0;
for i := 1 to Length(s) do
begin
if c = s[i] then tmp := i;
end;
result := tmp;
end;
function BaseToInt(const s: string; base: Integer): Integer;
var
digits: string;
i, temp: Integer;
begin
digits := '0123456789ABCDEF';
temp := 0;
for i := 1 to Length(s) do
begin
temp := base * temp;
Inc(temp, Position(s[i], digits) - 1);
end;
Result := temp;
end;
procedure TEditBox1.onKeyDown;
begin if Key.getAscii = 13 then begin
s1 := e1.text;
nombre := StrToInt(s1);
s2 := IntToBase(nombre, 2);
e2.text := s2;// j'en suis là
// le résultat ne s'affiche pas
end; end;
procedure TEditBox2.onKeyDown;
begin if Key.getAscii = 13 then begin
s2 := e2.text;
end; end;
procedure TEditBox3.onKeyDown;
begin if Key.getAscii = 13 then begin
s3 := e3.text;
end; end;
procedure TEditBox4.onKeyDown;
begin if Key.getAscii = 13 then begin
s4 := e4.text;
end; end;
procedure Cadre(xa, ya, l, h: Integer);
begin
_root.beginFill($f0f0f0);
_root.lineStyle(2,$808080);
_root.moveTo(xa , ya);
_root.lineTo(xa + l, ya);
_root.lineTo(xa + l, ya + h);
_root.lineTo(xa , ya + h);
_root.lineTo(xa , ya)
end;
begin
f := TextFormat.Create('Tahoma', 14);
f.color := $000000;
Cadre(10, 10, 32, 21);
Cadre(10, 38, 72, 21);
Cadre(10, 66, 32, 21);
Cadre(10, 94, 24, 21);
e1 := TEditBox1.Create(nil, 'input', 0, 10, 10 + 0 * (21 + 7), (3 + 1) * 8, 21);// décimal
e2 := TEditBox2.Create(nil, 'input', 1, 10, 10 + 1 * (21 + 7), (8 + 1) * 8, 21);// binaire
e3 := TEditBox3.Create(nil, 'input', 2, 10, 10 + 2 * (21 + 7), (3 + 1) * 8, 21);// octal
e4 := TEditBox4.Create(nil, 'input', 3, 10, 10 + 3 * (21 + 7), (2 + 1) * 8, 21);// hexadécimal
e1.setNewTextFormat(f);
e2.setNewTextFormat(f);
e3.setNewTextFormat(f);
e4.setNewTextFormat(f);
e1.type := 'input';
e2.type := 'input';
e3.type := 'input';
e4.type := 'input';
e1.text:='000';
e2.text:='00000000';
e3.text:='000';
e4.text:='00';
//Selection.setFocus(e1);
Key.addListener(e1);
Key.addListener(e2);
Key.addListener(e3);
Key.addListener(e4);
end. |
Partager