Recent

Author Topic: [SOLVED] Q: method replacement for MakeObjectInstance Win x64?  (Read 5323 times)

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Re: Q: method replacement for MakeObjectInstance Win x64?
« Reply #15 on: April 16, 2021, 05:27:23 pm »
Did forget to adapt the memo text in the Lazarus sample.
Correction attached.
Lazarus 3.2  FPC 3.2.2 Win10 64bit

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Q: method replacement for MakeObjectInstance Win x64?
« Reply #16 on: April 16, 2021, 07:27:41 pm »
.... after a couple of minutes i realized. hey, that's normal, it (the call of DragAcceptFiles) is done within the constructor = the handle is not yet accomplished!

In that case, I would move DragAcceptFiles() into an overridden CreateWnd() instead, eg:

Code: Pascal  [Select][+][-]
  1. protected
  2.   procedure CreateWnd; override;
  3.  
  4. procedure TMyCustomListView.CreateWnd;
  5. begin
  6.   inherited;
  7.   DragAcceptFiles(Handle, True);
  8. end;

Or, override CreateParams() to enable WS_EX_ACCEPTFILES, and not use DragAcceptFiles() at all:

Code: Pascal  [Select][+][-]
  1. protected
  2.   procedure CreateParams(var Params: TCreateParams); override;
  3.  
  4. procedure TMyCustomListView.CreateParams(var Params: TCreateParams);
  5. begin
  6.   inherited;
  7.   Params.ExStyle := Params.ExStyle or WS_EX_ACCEPTFILES;
  8. end;
  9.  

For the custom listview, i found the equivalent OnDropFiles property.

That event does not exist in Delphi.  If you are trying to write a component that works in both Delphi and FreePascal, you are going to have to write slightly different code for each compiler.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Re: [SOLVED] Q: method replacement for MakeObjectInstance Win x64?
« Reply #17 on: April 16, 2021, 08:39:32 pm »
Quote
I would move DragAcceptFiles() into an overridden CreateWnd() instead
...
Or, override CreateParams() to enable WS_EX_ACCEPTFILES, and not use DragAcceptFiles() at all

Yes, works, can confirm!

Quote
f you are trying to write a component that works in both Delphi and FreePascal. ..

That was not the intention behind; it was only for to contribute findings (here: about the difference).

Many thanks Remy for your detailed tips - and to all others who shared interest by reading or by contributions. It's great!  :D

Lazarus 3.2  FPC 3.2.2 Win10 64bit

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Re: [SOLVED] Q: method replacement for MakeObjectInstance Win x64?
« Reply #18 on: April 17, 2021, 11:08:48 am »
Maybe i had been a little bit to euphemistic regarding the working of this little test case (yes, this is a drawback of small test cases), because here all necessary things are within one pas file resp. the main form unit. Transfering to real life resp. to constructs with encapsulated components subsequent requirements might appear.
Maybe i'll open another "how to" thread for that (as being definitiely distinct from the issue of this inital OP), because it might be interesting for other newbies like me too.
Lazarus 3.2  FPC 3.2.2 Win10 64bit

 

TinyPortal © 2005-2018