private
{ Private declarations }
procedure pmSetInputProps(var Msg: TMessage); message WM_USER +123;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.pmSetInputProps(var Msg: TMessage); //message WM_USER +123;
var
i : integer;
ed : TEdit;
frm : TForm;
begin
// Msg.WParam sets the MaxLength
// Msg.LParam sets the PasswordChar
if (Msg.WParam <> 0) or (Msg.LParam <> 0) then begin
frm := Screen.ActiveForm;
if (frm <> nil) and (frm <> Self) then begin
ed := nil;
i := 0;
while (i < frm.ComponentCount) and (ed = nil) do begin
if frm.Components[i] is TEdit then
ed := TEdit(frm.Components[i]);
Inc(i);
end;
if ed <> nil then begin
if Msg.WParam <> 0 then
ed.MaxLength := Msg.WParam;
if Msg.LParam <> 0 then
ed.PasswordChar := char(Msg.LParam);
end;
end;
end;
end;
//Example...
procedure TForm1.Button1Click(Sender: TObject);
var
s : string;
begin
(*
//set the maxlength only
PostMessage(Handle, WM_USER +123, 8, 0); //maxlength = 8
//set the password char only
PostMessage(Handle, WM_USER +123, 0, ord('*')); //passwordchar = '*'
*)
//set maxlength and password char
PostMessage(Handle, WM_USER +123, 8, ord('*')); //maxlength = 8, passwordchar = '*'
s := InputBox('Password', 'Enter password...', '');
if s <> '' then
Edit1.Text := s;
end;