The code below defines a TcxDBBlobEdit
descendantwith its own OnKeyPress
.
My issue is that this OnKeyPress
(‘breakpoint here’) never gets triggered.
What am I overlooking?
type
TPasswordTcxDBBlobEdit = class(TcxDBBlobEdit) // DevExpress component
private
procedure SetPasswordMode(const Value: Boolean);
protected
FPasswordMode : Boolean;
FPasswordChar : Char;
FPrivateKeyFld: String;
procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
public
property PasswordMode: Boolean read FPasswordMode write SetPasswordMode;
property PasswordChar: Char write FPasswordChar;
property PrivateKeyFld: String write FPrivateKeyFld;
constructor Create(AOwner: TComponent); override;
procedure KeyPress(var Key: Char); override; Key: Char); override;
end;
{ TPasswordTcxDBBlobEdit }
constructor TPasswordTcxDBBlobEdit.Create(AOwner: TComponent);
begin
inherited;
FPasswordMode := false;
FPasswordChar := '*';
end;
procedure TPasswordTcxDBBlobEdit.KeyPress(var Key: Char);
var
lCtrl,
lShift,
lPaste: Boolean;
begin
if not FPasswordMode then Exit; // <-- Breakpoint here
lCtrl := (GetKeyState(VK_CONTROL) < 0); // High bit set
lShift := (GetKeyState(VK_SHIFT) < 0);
lPaste := lCtrl and ((Key = 'V') or (Key = 'v') or (Key = #$16)) // #$16 /questions/78928063/weird-16-value-for-v-character-in-onkeypress
or
lShift and (GetKeyState(VK_INSERT) < 0);
if not lPaste then
Key := #0;
inherited;
end;
The new component is created in the FormCreate:
procedure TDialoogEditProvider.FormCreate(Sender: TObject);
begin
FEditFTPPrivateKey := TPasswordTcxDBBlobEdit.Create(nil); // Before inherited because this assigns FEditFTPPrivateKey.DataBinding.DataSource/DataField
FEditFTPPrivateKey.PasswordMode := true;
FEditFTPPrivateKey.Parent := PanelFTP;
FEditFTPPrivateKey.Properties.BlobEditKind := bekMemo;
FEditFTPPrivateKey.Properties.BlobPaintStyle := bpsText;
FEditFTPPrivateKey.Properties.ImmediateDropDownWhenActivated := False;
FEditFTPPrivateKey.TabOrder := ComboFTPType.TabOrder + 1;
FEditFTPPrivateKey.Width := ComboFTPType.Width;
FEditFTPPrivateKey.Height := ComboFTPType.Height;
FEditFTPPrivateKey.Left := ComboFTPType.Left;
FEditFTPPrivateKey.Top := ComboFTPType.Top + ComboFTPType.Height + 4;
FEditFTPPrivateKey.ScrollBars := ssVertical;
FEditFTPPrivateKey.Hint := sReadOnlyButPaste;
inherited;
end;
- This is a Delphi 12 64-bits app
Assigned(FEditFTPPrivateKey.OnKeyPress)
is true at the end of theFormCreate
3
BrakNicku’s comment did the trick:
Inheritance is
TcxDBBlobEdit
– > TcxCustomBlobEdit
-> TcxCustomPopUpEdit
It is a popup editor of type (Tcx)Memo
and that needs the OnKeypress
handler.
Working code is now:
type
TPasswordTcxDBBlobEdit = class(TcxDBBlobEdit)
private
procedure SetPasswordMode(const Value: Boolean);
procedure MemoKeyPress(Sender: TObject; var Key: Char);
protected
FPasswordMode : Boolean;
FPasswordChar : Char;
FPrivateKeyFld: String;
procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
public
property PasswordMode: Boolean read FPasswordMode write SetPasswordMode;
property PasswordChar: Char write FPasswordChar;
property PrivateKeyFld: String write FPrivateKeyFld;
constructor Create(AOwner: TComponent); override;
procedure PropertiesPopup(Sender: TObject);
end;
procedure TPasswordTcxDBBlobEdit.PropertiesPopup(Sender: TObject);
begin
((Sender as TcxDBBlobEdit).Properties.PopupControl as TcxPopupMemo).OnKeyPress := MemoKeyPress;
inherited;
end;
procedure TPasswordTcxDBBlobEdit.MemoKeyPress(Sender: TObject; var Key: Char);
var
lCtrl,
lShift,
lPaste: Boolean;
begin
if not FPasswordMode then Exit; // Alles toegestaan
lCtrl := (GetKeyState(VK_CONTROL) < 0); // High bit set
lShift := (GetKeyState(VK_SHIFT) < 0);
lPaste := lCtrl and ((Key = 'V') or (Key = 'v') or (Key = #$16)) // #$16 /questions/78928063/weird-16-value-for-v-character-in-onkeypress
or
lShift and (GetKeyState(VK_INSERT) < 0);
if not lPaste then
Key := #0;
inherited;
end;
(Updated title and added DevExpress tag to the question because this is relevant)