开发者

Why does Clipboard.HasFormat( CF_HDROP ) return false in FormCreate

Why does Clipboard.HasFormat( CF_HDROP ) return false in FormCreate even though the clipboard contains Shell formats?

Edit

procedure TFormMain.FormCreate( Sender: TObject );
begin
  if Clipboard.HasFormat( CF_HDROP ) then
    MessageDlg( 'true', mtInformation, [ mbOK ], 0 )
  else
    MessageDlg( 'false', mtInformation, [ mbOK ], 0 );
end;

This returns false but MyIdleHandler returns true:

Application.OnIdle := MyIdleHandler; 

procedure TFormMain.MyIdleH开发者_JAVA百科andler(Sender: TObject; var Done: Boolean); 
begin 
    Paste1.Enabled := Clipboard.HasFormat( CF_HDROP ); 
end;


It returns true. I don't know if you can/should apply it to the Paste1 button (or whatever it is) until the form has been created, but this shows that it DOES return true, if there's a file object on the clipboard:

procedure TForm2.FormCreate(Sender: TObject);
begin
  if  Clipboard.HasFormat( CF_HDROP ) then
    MessageDlg('true', mtInformation, [mbOK], 0)
  else
    MessageDlg('false', mtInformation, [mbOK], 0);
end;

In my case, it shows "true" if I first copy a file to the clipboard, false otherwise.


The problem is most likely not the one you think it is.

Clipboard.HasFormat(CF_HDROP);

is probably true even in your FormCreate procedure. Try this with

procedure TForm1.FormCreate(Sender: TObject);
begin
  if Clipboard.HasFormat(CF_HDROP) then
    ShowMessage('Yes, Rejbrand was right!');
end;

The rest of my answer assumes that Paste1 is a TAction, which it should be. But most likely it is a menu item, isn't it? A good advice is to start using the TActionList and TActions.

The problem is most likely that the action isn't redy to be used yet.

After all, SomeAction.Enabled := <something> statements are supposed to be run in the OnUpdate events of the corresponding actions. For instance,

procedure TForm1.ActionPasteExecute(Sender: TObject);
begin
  RichEdit1.Paste;
end;

procedure TForm1.ActionPasteUpdate(Sender: TObject);
begin
  ActionPaste.Enabled := Clipboard.HasFormat(CF_TEXT);
end;

The OnUpdate event is executed exactly when the status of the action needs to be determined, e.g. when a popup menu containing a menu item with the action is shown.


Clipboard.HasFormat works fine. Your problem lies elsewhere.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜