How to catch Paste command and change text of Clipboard before that text is pasted into a TMemo
, but, after Paste, text in Clipboard must be same like before changing?
Example, Clipboard have text 'Simple Question'
, text that go in the TMemo
is 'Симплe Qуeстиoн'
, and after that text in Clipboard is like before changing, 'Simple Question'
.
This is an alternative to Sertac's excellent answer, which is to override the control's WndProc:
// For detecting WM_PASTE messages on the control
OriginalMemoWindowProc: TWndMethod;
procedure NewMemoWindowProc(var Message: TMessage);
//...
// In the form's OnCreate procedure:
// Hijack the control's WindowProc in order to detect WM_PASTE messages
OriginalMemoWindowProc := myMemo.WindowProc;
myMemo.WindowProc := NewMemoWindowProc;
//...
procedure TfrmMyForm.NewMemoWindowProc(var Message: TMessage);
var
bProcessMessage: Boolean;
begin
bProcessMessage := True;
if (Message.Msg = WM_PASTE) then
begin
// Data pasted into the memo!
if (SomeCondition) then
bProcessMessage := False; // Do not process this message any further!
end;
if (bProcessMessage) then
begin
// Ensure all (valid) messages are handled!
OriginalMemoWindowProc(Message);
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With