Did the same thing in D7. Compiles fine, but entering into the
InputQuery shows the letters being entered instead of the *
characters.
How can I make this work as it does in D3?
Do you need to set a directory option (which may be different in D7)
to make the compiler look in the app's directory.
I would have thought you would be better adding an "InputQueryPW" in
the D7 dialogs.pas additional to the basic "InputQuery", rather than
making a local dialogs.pas. Or alternatively lifting the code of
InputQuery, modifying it to "InputQueryPW", and putting it in your
app's source code.
Alan Lloyd
I tested for that by making an intentional error (just removed a
semicolon) in the dialogs.pas in the app's directory. Compiler broke
on it, so D7 is using the local dialogs.pas, just like in D3.
> I would have thought you would be better adding an "InputQueryPW" in
> the D7 dialogs.pas additional to the basic "InputQuery", rather than
> making a local dialogs.pas.
Good idea, I will try that later today.
> Or alternatively lifting the code of
> InputQuery, modifying it to "InputQueryPW", and putting it in your
> app's source code.
I'm not sure how to do that .. but I'll give it a try if the above
doesn't work.
Buddy
Add "Consts" to your form's implementation uses clause (its needed by
the buttons in the dialog). Then add to your implementation code . . .
function GetAveCharSize(Canvas: TCanvas): TPoint;
{used by InputQueryPW}
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 InputQueryPW(const ACaption, APrompt: string;
var Value: string; {add parameter} PWChar : Char): Boolean;
{copied from Dialogs.pas & modified}
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;
DialogUnits := GetAveCharSize(Canvas);
BorderStyle := bsDialog;
Caption := ACaption;
ClientWidth := MulDiv(180, DialogUnits.X, 4);
ClientHeight := MulDiv(63, DialogUnits.Y, 8);
Position := poScreenCenter;
Prompt := TLabel.Create(Form);
with Prompt do
begin
Parent := Form;
AutoSize := True;
Left := MulDiv(8, DialogUnits.X, 4);
Top := MulDiv(8, DialogUnits.Y, 8);
Caption := APrompt;
end;
Edit := TEdit.Create(Form);
with Edit do
begin
Parent := Form;
Left := Prompt.Left;
Top := MulDiv(19, DialogUnits.Y, 8);
Width := MulDiv(164, DialogUnits.X, 4);
MaxLength := 255;
PasswordChar := PWChar; // add this line
Text := Value;
SelectAll;
end;
ButtonTop := MulDiv(41, DialogUnits.Y, 8);
ButtonWidth := MulDiv(50, DialogUnits.X, 4);
ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
with TButton.Create(Form) do
begin
Parent := Form;
Caption := SMsgDlgOK;
ModalResult := mrOk;
Default := True;
SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop,
ButtonWidth,
ButtonHeight);
end;
with TButton.Create(Form) do
begin
Parent := Form;
Caption := SMsgDlgCancel;
ModalResult := mrCancel;
Cancel := True;
SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop,
ButtonWidth,
ButtonHeight);
end;
if ShowModal = mrOk then
begin
Value := Edit.Text;
Result := True;
end;
finally
Form.Free;
end;
end;
Use by calling as InputQuery but add '*' as the PWChar parameter. If
you want normal edit display use '#0' as this parameter.
Alan Lloyd
Rather than change the behavior of the function in Dialog.pas, why not
just have your own function? Copy the InputQuery function from
Dialogs.pas and paste it into your own unit, and then make whatever
changes you need.
Looks like you'll also need to copy the GetAveCharSize function, but I
don't see anything else you might be missing.
Don't make a copy of a Delphi-provided unit unless you really need to.
It can lead to having to recompile any number of other Delphi units,
even if you haven't changed them.
--
Rob
Also "Consts" for D3 when I checked the code I posted.
Alan Lloyd