我现在有个系统,其中有个修密码的子程序,我用的是INPUTBOX来进行实现,但是由INPUTBOX不是窗体,所以输入的数据都是直接显示的,我要的是在INPUTBOX中也能实现这个密码只显示为*!
   或者说设定不管键盘输入什么数据,我都回显*,而我输入的数据都还存在,能调用!

解决方案 »

  1.   

    要么自己做一个输入框,要么修改 function InputQuery源码
      

  2.   

    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
      

  3.   

    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;
      

  4.   

    楼上的好复杂
    如果要实现楼主说的话,不知道这样可以不?
    我用个临时的string来保存用户的输入,然后在每次inputbox改变(change)的时候,增加或减少其中的星号,同时修改临时string里面的值
      

  5.   

    可以了,不过我用的是INPUTBOX,它还是原数据直接显示,最后我把INPUTQUERY的返回值改成STRING ,然后就YEAH!OK!不过有些资源浪费了,
    还是谢谢你