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
|
{ Transpositions.pas
Exemple Flash-Pascal
R. Chastain }
program Transpositions;
uses
Flash8;
{$FRAME_WIDTH 600}
{$FRAME_HEIGHT 400}
type
TEditBox = class(TextField)
procedure onKeyDown;
end;
var
e: TEditBox;
t: TextField;
s: string;
c: integer;
function Transpose(pS: string; n: integer): string;
var
temp: string;
i, L: integer;
begin
temp := '';
{ Par exemple,
si pS = 'abcde'
et n = 3
alors }
L := Length(pS);
{ L = 5 }
for i := 1 to L - n do temp := temp + pS[i];
{ temp = 'ab' }
temp := temp + pS[l];
{ temp = 'ab' + 'e' }
for i := L - n + 2 to L do temp := temp + pS[i - 1];
{ temp = 'abe' + 'cd' }
result := temp;
{ result = 'abecd' }
end;
procedure Generateur(pS: string; n: integer);
var
i: integer;
temp: string;
begin
temp := pS;
for i := 1 to n do
begin
temp := Transpose(temp, n);
if n = 1 then
begin
Inc(c);
t.text := t.text + temp + ' ' + IntToStr(c) + #13
end
else
Generateur(temp, n - 1);
end;
end;
procedure TEditBox.onKeyDown;
begin
if Key.getAscii = 13 then
begin
s := e.text;
t.text := ''; c := 0;
Generateur(s, Length(s));
end;
end;
begin
with TextField.Create(_root, 'label', 0, 0, 0, Stage.Width-1, 4*16+4) do
begin
setNewTextFormat(TextFormat.Create('Courier New', 12));
text := "Transpositions d'une chaîne de caractères."#13
+ 'Programme Flash-Pascal.'#13
+ 'Votre saisie ?';
end;
e := TEditBox.Create(_root, 'input', 1, 0, 3*16+4, Stage.Width-1, 16+4);
e.setNewTextFormat(textFormat.Create('Courier New', 12));
e.type := 'input';
e.border := true;
Selection.setFocus(e);
Key.addListener(e);
t := TextField.Create(_root, 'output', 2, 0, 3*16+4+16+4, Stage.Width-1,
Stage.Height - (3*16+4+16+4));
t.SetNewTextFormat(TextFormat.Create('Courier New', 12));
t.text := '';
c := 0;
end. |
Partager