Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

password char in memo 1

Status
Not open for further replies.

earlrainer

Programmer
Mar 1, 2002
170
IN
Hello guys ,

in Tedit we can set passwordchar property to hide user input.
can the same be done with a tmemo ?

thanks
 
Not directly. I don't know why you would want to password character a TMemo, but what you want to do is through the KeyPress event.

Code:
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  { filter out a few special key characters like tab,
    return, backspace, etc }
  if Key in [#9, #10, #13, #8] then
    exit
  else
    Key := '#';
end;
 
I forgot...of course, before you do this you want to save the key that was actually pressed someplace else, that depends on what you want to do with the TMemo, of course.
 
Even better, I got to playing around. ShowMemo and RealMemo are both TMemo, ShowMemo is what the user gets to see, RealMemo holds what they actually typed.

Code:
procedure TForm1.ShowMemoKeyPress(Sender: TObject; var Key: Char);
begin
  RealMemo.Perform(wm_char, Byte(Key), 0);
  if Key in [#9, #10, #13, #8] then
    exit
  else
    Key := '#';
end;
 
Hi Glenn ,
that was brilliant.
just one minor hitch , when i delete from first memo it does not delete from the other because of the exit ,any work around that.
Thank a lot for your help Glenn
 
Keys like Delete, Home, and End weren't caught in the KeyPress event. They, however, are caught in the KeyDown event. Hopefully adding this will work:

Code:
procedure TForm1.ShowMemoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  RealMemo.Perform(wm_keydown, Key, 0);
  RealMemo.Perform(wm_keyup, key, 0);
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top