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
| unit UMyDialogs;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,consts;
function InputQuery(const ACaption, APrompt: string;var Value: currency): Boolean;
function InputBox(const ACaption, APrompt : String; ADefault: currency): currency;
implementation
//cette fonction doit etre palce ici a chercher dans l'unite dialogs
function GetAveCharSize(Canvas: TCanvas): TPoint;
...
// la c'est la gestion des touches
procedure OnMyKeyPress(Self : TForm;Sender: TObject; var Key: Char);
begin
if not (Key in ['+', '-', DecimalSeparator, '0'..'9', #0..#31] )
or ((key = decimalseparator) and (pos(decimalseparator,(sender as TEdit).text)>0))then
begin
Key := #0;
MessageBeep(MB_ICONEXCLAMATION);
end
end;
function InputQuery(const ACaption, APrompt: string;var Value : Currency): Boolean;
var
...
EvtKeyPress: TKeyPressEvent;
begin
...
Edit := TEdit.Create(Form);
with Edit do
begin
// bon la ca se complique
// le but c'est de definir la procedure comme une methode de class
TMethod(EvtKeyPress).Code := @OnMyKeyPress;
TMethod(EvtKeyPress).Data := Form;
...
Text := floattostr(Value);
// la on l'afffecte a l'evenement onkeypress
OnKeyPress := EvtKeyPress;
end;
...
if ShowModal = mrOk then
begin
Value := strtofloat(Edit.Text);
Result := True;
end;
...
end;
function InputBox(const ACaption, APrompt : string; ADefault: currency): currency;
begin
Result := ADefault;
InputQuery(ACaption, APrompt, Result);
end;
end. |
Partager