InputQuery

王朝百科·作者佚名  2012-04-09  
宽屏版  字体: |||超大  

函数功能InputQuery里输入的字显示为密码“*”

函数原型实例function InputQuery(const ACaption, APrompt: string;

var Value: string): Boolean;

function GetAveCharSize(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;

var

Form: TForm;

Prompt: TLabel;

Edit: TEdit;

DialogUnits: TPoint;

ButtonTop, ButtonWidth, ButtonHeight: Integer;

begin

Result := False;

Form := TForm.Create(Application);

with Form do

try

Canvas.Font := Font;

Font.Charset := GB2312_CHARSET;

Font.Size := 9;

DialogUnits := GetAveCharSize(Canvas);

BorderStyle := bsDialog;

Caption := ACaption;

ClientWidth := MulDiv(180, DialogUnits.X, 4);

Position := poScreenCenter;

Prompt := TLabel.Create(Form);

with Prompt do

begin

Parent := Form;

Caption := APrompt;

Left := MulDiv(8, DialogUnits.X, 4);

Top := MulDiv(8, DialogUnits.Y, 8);

Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4);

WordWrap := True;

end;

Edit := TEdit.Create(Form);

with Edit do

begin

PasswordChar := '*';

Parent := Form;

Left := Prompt.Left;

Top := Prompt.Top + Prompt.Height + 5;

Width := MulDiv(164, DialogUnits.X, 4);

MaxLength := 255;

Text := Value;

SelectAll;

end;

ButtonTop := Edit.Top + Edit.Height + 15;

ButtonWidth := MulDiv(50, DialogUnits.X, 4);

ButtonHeight := MulDiv(14, DialogUnits.Y, 8);

with TButton.Create(Form) do

begin

Parent := Form;

Caption := '取消';

ModalResult := mrCancel;

Cancel := True;

SetBounds(MulDiv(92, DialogUnits.X, 4), Edit.Top + Edit.Height + 15,

ButtonWidth, ButtonHeight);

Form.ClientHeight := Top + Height + 13;

Left := (Edit.Left + Edit.Width) - Width;

end;

with TButton.Create(Form) do

begin

Parent := Form;

Caption := '确定';

ModalResult := mrOk;

Default := True;

SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,

ButtonHeight);

Left := (Edit.Left + Edit.Width) - (Width * 2) - 4;

end;

if ShowModal = mrOk then

begin

Value := Edit.Text;

Result := True;

end;

finally

Form.Free;

end;

end;

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝百科 版权所有