Clearing clipboard part 2 ...

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Clearing clipboard part 2 ...

Postby Marloes » Sat Sep 05, 2015 5:39 am

As a result of the Clearing Clipboard thread I tried but got some errors. Now I seem to have finally figured out what, but can somebody please explain why?

Start a blank project and put the following code in the constructor of Form1.
Code: Select all
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXClipboardService)))
{
   _di_IFMXClipboardService Clipboard = TPlatformServices::Current->GetPlatformService(__uuidof(IFMXClipboardService));
   Clipboard->SetClipboard(TValue::From<String>(""));
}


When you run the form is created and that is that.

Now go into compiler options. Uncheck "Link with runtime packages" (under Packages). Run again. Now you should get the same error I got before.

What is happening here? Obviously, I do not know the FireMonkey framework well enough to completely understand what is happening here so I would really appreciate it if something could enlighten me.
Marloes
Active Poster
Active Poster
 
Posts: 13
Joined: Mon Dec 01, 2014 5:35 am

Re: Clearing clipboard part 2 ...

Postby Marloes » Sat Sep 05, 2015 7:39 am

After a lot of research I found the problem. Turns out this is due to a known compiler bug. Replacing the code with this code works

Code: Select all
   if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXClipboardService)))
   {
      _di_IFMXClipboardService Clipboard = TPlatformServices::Current->GetPlatformService(__uuidof(IFMXClipboardService));
      Clipboard->SetClipboard(TValue::FromVariant(toClipboard));
   }
Marloes
Active Poster
Active Poster
 
Posts: 13
Joined: Mon Dec 01, 2014 5:35 am

Re: Clearing clipboard part 2 ...

Postby smd » Sat Sep 05, 2015 12:57 pm

In my original post about clearing clipboard, I am using the code in a normal function. I call that function at various parts of my program, or when the operation is selected by the user. The problem you are encountering may be due to doing it in the constructor. Try just making a function, then at OnFormActivate call the function. That gives everything a chance to initialize.
-----------------------------
Scott
smd
BCBJ Guru
BCBJ Guru
 
Posts: 130
Joined: Sat Nov 29, 2014 8:02 pm
Location: Las Vegas


Return to Technical

Who is online

Users browsing this forum: Baidu [Spider] and 4 guests