function GetAveCharSize2(Canvas: TCanvas): TPoint;
var
I: Integer;
Buffer: array[0..51] of Char;
begin
for I := 0 to 25 do Buffer[I] := Chr(I + Ord('A'));
for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));
GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
Result.X := Result.X div 52;
end;
Function dfn_dcl_button2(const titlu_cutie,
APrompt:string;
mesajul_buton_yes:string;
yeslatime:integer;{0.default/else.ok}
mesajul_buton_no:string;
nolatime:integer;{0.default/else.ok}
latimea_ferestrei:integer;
inaltimea_ferestrei:integer
): Char;
var
msj_prompt:string;
de_sus_in_jos:integer;
pozitia_butoanelor :integer;
s3m:string;
leny,lenn:integer;
latime_buton,ucsxdir,ucsydir:integer;
Form: TForm;
Prompt:array[1..15] of TLabel;
DialogUnits: TPoint;
ButtonTop, ButtonWidth, ButtonHeight: Integer;
Function creaza_okaiulul:integer;
begin
with TButton.Create(Form) do
begin
Parent := Form;
Caption :=mesajul_buton_yes;
ModalResult := mrOk;
Default := True;
SetBounds(MulDiv(pozitia_butoanelor, DialogUnits.X, 4),
ButtonTop,
yeslatime,
ButtonHeight);
result:=ButtonTop+ButtonHeight div 2;
pozitia_butoanelor:=pozitia_butoanelor+10+yeslatime;
end;
end;
procedure creaza_cancelurul;
begin
with TButton.Create(Form) do
begin
Parent := Form;
Caption := mesajul_buton_no;
ModalResult := mrCancel;
Cancel := True;
SetBounds(MulDiv(pozitia_butoanelor, DialogUnits.X, 4),
ButtonTop,
nolatime,
ButtonHeight);
pozitia_butoanelor:=pozitia_butoanelor+10+nolatime;
ucsxdir:=Left;
ucsydir:=Top;
end;
end;
procedure creaza_promptolira;
var i,j:integer;q:pchar;
begin
s3m:=msj_prompt;
j:=15;
i:=01;
while (i>0) do
begin
q:=pchar(msj_prompt);
i:=pos(#10,msj_prompt);
if (i>0)
then begin s3m:=copy(msj_prompt,1,i-1);
inc(q,i);
msj_prompt:=strpas(q);
i:=2;
end
else s3m:=msj_prompt;
Prompt[j] := TLabel.Create(Form);
with Prompt[j] do
begin
Parent := Form;
AutoSize := True;
Left := MulDiv(8, DialogUnits.X, 4);
Top := MulDiv(de_sus_in_jos, DialogUnits.Y, 8);
Caption := s3m;
end;
dec(j);
if (j<2) then j:=1;
inc(de_sus_in_jos,12);
dec(i);
if (j<1) then i:=0;
end;{while}
end;
procedure pozitoneaza_butonasele;
begin
ButtonTop := MulDiv(de_sus_in_jos, DialogUnits.Y, 8);
ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
inc(de_sus_in_jos,21);
end;
begin
if (length(mesajul_buton_yes)<2) then mesajul_buton_yes:='Yes';
if (length(mesajul_buton_no)<2) then mesajul_buton_no:='No';
leny:=length(mesajul_buton_yes);
lenn:=length(mesajul_buton_no);
case inaltimea_ferestrei of
0..1: inaltimea_ferestrei:=200;
else
end; {case}
case latimea_ferestrei of
0..1: latimea_ferestrei:=164;
else
end; {case}
de_sus_in_jos :=11;
msj_prompt :=APrompt;
pozitia_butoanelor:=38;
if (length(msj_prompt)<2) then msj_prompt:='Prompt';
pozitia_butoanelor:= 38;
if (msj_prompt[1]='#') and ((msj_prompt[5] in ['1'..'F']))
then pozitia_butoanelor:=ord(msj_prompt[5]) - ord('0')*10;
result := 'e';
Form := TForm.Create(Application);
with Form do
try
Canvas.Font := Font;
DialogUnits := GetAveCharSize2(Canvas);
BorderStyle := bsDialog;
Caption := titlu_cutie;
ClientWidth := MulDiv(latimea_ferestrei , DialogUnits.X, 4);
ClientHeight := MulDiv(inaltimea_ferestrei, DialogUnits.Y, 8);
Position := poScreenCenter;
if (msj_prompt<>'none') then
creaza_promptolira;
pozitoneaza_butonasele;
if (yeslatime<1) then yeslatime:=60+leny;
yeslatime:=MulDiv(yeslatime, DialogUnits.X, 4);
if (nolatime<1) then nolatime:=60+lenn;
nolatime :=MulDiv(nolatime, DialogUnits.X, 4);
creaza_okaiulul;
SetCursorPos(Screen.width div 2,Screen.height div 2);
// SetCursorPos(100,300);
creaza_cancelurul;
result:='n';
if (ShowModal = mrOk) then result:='y';
finally
Form.Free;
end;
end;