Board index » delphi » Using Cut/Copy/Paste from Main Menu

Using Cut/Copy/Paste from Main Menu

I want to enable Cut/Copy/Paste from the Edit menu on my main form.
I do know know what control my user's cursor will be in when calling this
however.

I thought I could use this code:

        Screen.ActiveControl.CutToClipBoard;

But this generates an error message.

Thanks in advance for any help!

Eric
reply to following address (replace _NOSPAM_ with dot)
eric@thorsoft_NOSPAM_com

 

Re:Using Cut/Copy/Paste from Main Menu


Quote
>I want to enable Cut/Copy/Paste from the Edit menu on my main form.
>I do know know what control my user's cursor will be in when calling this
>however.

>I thought I could use this code:

>        Screen.ActiveControl.CutToClipBoard;

>But this generates an error message.

>Thanks in advance for any help!

>Eric
>reply to following address (replace _NOSPAM_ with dot)
>eric@thorsoft_NOSPAM_com

Eric:

There is probably a more elegant way to do this but this is what I use. I
expect that the problem is that Screen.ActiveControl is of type TWinControl,
which lacks the "CutToClipBoard" method. I think you need to know about the
'is' and 'as' operators, if you don't already.

Sample:

if Screen.ActiveControl is TEdit then
  (Screen.ActiveControl as TEdit).CutToClipboard
else if Screen.ActiveControl is TMemo then
  (Screen.ActiveControl as TMemo).CutToClipboard

... etc

You can also do this more neatly by handling exceptions but this may be
enough to get you rolling.

Bill

Other Threads