Pregunta

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...

¿Fue útil?

Solución

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?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top