Question:
How to capture clipboard content?
Answer:
I give you an example to folow.
Make new project, and place TImage and TMemo.
Those object will use to show clipboard content, if Image will shows at Image1 and if text will shows at Memo1.
uses Clipboard;
...
procedure TForm1.Button1Click(Sender: TObject);
var
MyHandle: THandle;
begin
Clipboard.Open;
if Clipboard.HasFormat(CF_TEXT) then
begin
MyHandle:=Clipboard.GetAsHandle(CF_TEXT);
Memo1.Lines.Add(StrPas(GlobalLock(MyHandle)));
GlobalUnlock(MyHandle);
end;
if (Clipboard.HasFormat(CF_BITMAP)) or
(Clipboard.HasFormat(CF_PICTURE)) then
Image1.Picture.Assign(Clipboard);
Clipboard.Close;
end;
Showing posts with label clipboard. Show all posts
Showing posts with label clipboard. Show all posts
Question:
Do you have method to prevent user pasting something to my memo?
Answer:
You can detect keypress and clear the clipboard.
uses Clipbrd;
...
procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if ((Key=Ord('V'))and(ssCtrl in Shift)) then
begin
Clipboard.Clear;
Memo1.SelText:='Delphi tricks rules!';
Key:=0;
end;
end;
Question:
Please provide easiest way to copy paste from TMemo.
Answer:
Just use VCL command.
Like this ...
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.SelectAll;
Memo1.CopyToClipboard;
Memo1.Clear;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo2.PasteFromClipboard;
end;
Subscribe to:
Comments (Atom)