1

So I want to add a Copy/Paste function to my Delphi application that draws different shapes and does stuff with them.

Here's the on even handler for the Copy menu item:

procedure TForm1.Copy1Click(Sender: TObject);
begin
  Clipboard.Open;
  if SelectShape <> nil then
      clipboard.SetComponent(SelectShape);
   Clipboard.Close;
  end;

And I get the error:

       Incompatible types: 'TComponent' and 'TBaseShape'  

TBaseShape is the ancestor class for all shapes in my application

I have no idea why it doesn't work...

FIXER91
  • 13
  • 3
  • 7
    To get it to work, your `TBaseShape` class would have to be `TComponent` class descendant, which is not. – TLama Dec 29 '13 at 19:07
  • 1
    Also, if `SelectShape` is nil, consider calling `TClipboard.Clear()`, or simply don't open/close the clipboard to begin with. – Remy Lebeau Dec 29 '13 at 20:25

1 Answers1

3

Another approach would be to use a private data format, and serialize your object to XML or another easy-to-debug text-based structure, and put that onto the clipboard. It would also be useful/polite to render your object (assuming it's a graphic of some sort) onto a Bitmap, and place that on the clipboard as well (clipboard can hold multiple/many formats simultaneously) so that the user can paste into paint, word, etc., and get "something".
Here's a question that does something along these lines, using GPX data

How to paste a custom format clipboard data into a TMemo?

Community
  • 1
  • 1
Chris Thornton
  • 15,620
  • 5
  • 37
  • 62