function TForm1.Input_password(const ACaption, APrompt: string;<br> Value: string): string;<br> function GetAveCharSize(Canvas: TCanvas): TPoint;<br> var<br> I: Integer;<br> Buffer: array[0..51] of Char;<br> begin<br> for I := 0 to 25 do Buffer := Chr(I + Ord('A'));<br> for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));<br> GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));<br> Result.X := Result.X div 52;<br> end;<br><br>var<br> Form: TForm;<br> Prompt: TLabel;<br> Edit: TEdit;<br> DialogUnits: TPoint;<br> ButtonTop, ButtonWidth, ButtonHeight: Integer;<br>begin<br> Result := '';<br> Form := TForm.Create(nil);<br> //Windows.SetParent(Form.Handle ,Handle);<br> form.ParentWindow:= handle;<br> form.FormStyle:= fsStayOnTop;<br> with Form do<br> try<br> Canvas.Font := Font;<br> DialogUnits := GetAveCharSize(Canvas);<br> BorderStyle := bsDialog;<br> Caption := ACaption;<br> ClientWidth := MulDiv(180, DialogUnits.X, 4);<br> Position := poScreenCenter;<br> ParentWindow:= handle;<br> Prompt := TLabel.Create(Form);<br> with Prompt do<br> begin<br> Parent := Form;<br> Caption := APrompt;<br> Left := MulDiv(8, DialogUnits.X, 4);<br> Top := MulDiv(8, DialogUnits.Y, 8);<br> Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4);<br> WordWrap := True;<br> end;<br> Edit := TEdit.Create(Form);<br> with Edit do<br> begin<br> Parent := Form;<br> Left := Prompt.Left;<br> Top := Prompt.Top + Prompt.Height + 5;<br> Width := MulDiv(164, DialogUnits.X, 4);<br> passwordchar:= '*';<br> MaxLength := 255;<br> Text := Value;<br> SelectAll;<br> end;<br> ButtonTop := Edit.Top + Edit.Height + 15;<br> ButtonWidth := MulDiv(50, DialogUnits.X, 4);<br> ButtonHeight := MulDiv(14, DialogUnits.Y, 8);<br> with TButton.Create(Form) do<br> begin<br> Parent := Form;<br> Caption := '确定';<br> ModalResult := mrOk;<br> Default := True;<br> SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,<br> ButtonHeight);<br> end;<br> with TButton.Create(Form) do<br> begin<br> Parent := Form;<br> Caption := '取消';<br> ModalResult := mrCancel;<br> Cancel := True;<br> SetBounds(MulDiv(92, DialogUnits.X, 4), Edit.Top + Edit.Height + 15,<br> ButtonWidth, ButtonHeight);<br> Form.ClientHeight := Top + Height + 13;<br> end;<br> if ShowModal = mrOk then<br> begin<br> result := Edit.Text;<br> end;<br> finally<br> Form.Free;<br> end;<br>end;