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
| type
TClavierVirt = class(TPanel)
private
{ Private declarations }
Texte: TEdit;
KeyNum: array[0..9] of TBitBtn; // Jeu de 10 boutons numériques
protected
{ Protected declarations }
procedure BitBtnClick(Sender: TObject); // Redéfinition de la méthode Click d'un BitBtn
public
{ Public declarations }
constructor Create(TheOwner: TComponent); override;
published
{ Published declarations }
end;
procedure Register;
implementation
constructor TClavierVirt.Create(TheOwner: TComponent);
var
i, LBtn, HBtn: Integer;
begin
inherited Create (TheOwner);
...
for i:= 0 to 9 do
begin
KeyNum[i]:= TbitBtn.Create(Self);
with KeyNum[i] do
begin
Parent:= Self;
Top:= 60;
Width:= LBtn;
Height:= HBtn;
Left:= 8+i*(Width+8);
Font.Size:= 18;
Font.Style:= [fsBold];
Caption:= IntToStr((i+1) mod 10);
OnClick:= @BitBtnClick; // Assignation de la méthode Click
end;
end;
end;
procedure TClavierVirt.BitBtnClick(Sender: TObject);
var
S: String;
begin
S:= Texte.Text;
Insert( TBitBtn(Sender).Caption, S, Texte.CaretPos.X+1); // Insertion dans le texte du caractère du bouton choisi
Texte.Text:= S;
end; |
Partager