Recent

Author Topic: Q OnDropFile handling for components  (Read 1128 times)

d7_2_laz

  • Hero Member
  • *****
  • Posts: 510
Q OnDropFile handling for components
« on: April 17, 2021, 11:48:44 am »
Subsequently to this thread https://forum.lazarus.freepascal.org/index.php/topic,54099.0.html
--  transferring some code from the main form to other pas files that won't ccompil:

Doing within the construcor of "MyCustomListview"  or shortly after the constructor has been finished:
Code: Pascal  [Select][+][-]
  1. OnDropFiles := DoOnDropFiles;  // Won't compile! : "identifier not found : OnDropFiles"

It turns out that "OnDropFiles" is not a property of the custom listview (as i, for a short moment, did assume), but a property of Application, through which the dropiing is routed.
By that i get it back to work:
Code: Pascal  [Select][+][-]
  1. // "DoOnDropFiles" is a method of my custom listview class
  2. Application.OnDropFiles := DoOnDropFiles;  // does work

My question #1 is: is the conceptually ok to do so?

But: by that, an invocation of the callback won't be bound any longer to the instance. but to the class.

This does lead to question #2.
Assuming i have two instances of the class in speech opened on the form. And assuming i did for both (hard-coded for the moment in the main form, what i'm in fact won't like to do) a  "DragAcceptFiles(<componentname>,. true)":

If i drop a file from outside of the app onto listview_1. the callback DoOnDropFiles will be triggered for listview_1 ... and as well for listview_2 (as it's class related) - understandable -, allthough the drop did happen only onto listview_1.

Is this by concept or by my own false thinking; and howto assure that only listview_1 is the processed drop target? Does it need (from the perspective of a component) eg. to inquire if it has the focus before it starts to do something or not?  I'd like to try to avoid as less as possible coding about that in the main form.
The mai form should not necessary the instance or class names of such objects (encapsulation).
Lazarus 3.2  FPC 3.2.2 Win10 64bit

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1111
  • Professional amateur ;-P
Re: Q OnDropFile handling for components
« Reply #1 on: April 17, 2021, 12:58:24 pm »
Hey d7_2_laz,

I can't really help you on your question, quite sorry about that.

But looking at your code something is really bugging me in terms of not knowing what mode you're in.

Just FYI:
Code: Pascal  [Select][+][-]
  1. {$mode delphi} //<- Look at me
  2. SomeComponent.OnSomeEvent:= MySomeEvenHandle; // <--correct

BUT

Code: Pascal  [Select][+][-]
  1. {$mode objfpc} //<- Look at me
  2. SomeComponent.OnSomeEvent:= MySomeEvenHandle; // <--IN-correct
  3. SomeComponent.OnSomeEvent:= @MySomeEvenHandle; // <--correct

I'm sorry if this is a bit off-topic, but it was bugging me and I needed to make it clear.

If this doesn't help, I profoundly apologize for butting my nose in.

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

d7_2_laz

  • Hero Member
  • *****
  • Posts: 510
Re: Q OnDropFile handling for components
« Reply #2 on: April 17, 2021, 01:52:25 pm »
Hello Gus, no problem!
Yes, it's known, As i imported apps from Delphi and so oftenly have Mode Delphi, i mentioned that in the linked article (with a small typo, hm):
Code: Pascal  [Select][+][-]
  1.  OnDropFiles := DoOnDropFiles;  // Symtax: Mode Delphi

Mode FPC would require  "OnDropFiles := @DoOnDropFiles", true.
Lazarus 3.2  FPC 3.2.2 Win10 64bit

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1111
  • Professional amateur ;-P
Re: Q OnDropFile handling for components
« Reply #3 on: April 17, 2021, 08:30:03 pm »
Hey d7_2_laz,

Yes, it's known, As i imported apps from Delphi and so oftenly have Mode Delphi, i mentioned that in the linked article (with a small typo, hm):

It's becoming apparent that I shove my foot in my mouth more than I should :)

I'm sorry for not having a look on the linked article, mea culpa!!

Well, at least you have one less thing to worry about :)

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

 

TinyPortal © 2005-2018