Recent

Author Topic: Multiple file properties and Drag and Drop  (Read 5017 times)

HomeBoy38

  • Jr. Member
  • **
  • Posts: 59
Multiple file properties and Drag and Drop
« on: August 15, 2018, 09:19:55 pm »
Hi,

I am porting a Delphi app to Lazarus and I face 2 issues.

- DoDragDrop(DataObject, Self as IDropSource, DROPEFFECT_COPY, Effect);
(code used from https://www.swissdelphicenter.ch/en/showcode.php?id=2335)

This cause my application to crash as soon as I start the D&D operation.

- SHMultiFileProperties(Data, 0);
(code used from https://www.swissdelphicenter.ch/en/showcode.php?id=2425)

The files properties opened are not correct, it seems to count My Documents folder as many times as the number of files selected.

I tried a lot more codes but they do not compile...

I am not a big dev guy, I am only doing simple applications :) so all help is appreciated (even if I may not understand it)!

Thanks!!!
« Last Edit: September 04, 2018, 03:42:23 pm by HomeBoy38 »

HomeBoy38

  • Jr. Member
  • **
  • Posts: 59
Re: Multiple file properties and Drag and Drop
« Reply #1 on: September 04, 2018, 05:05:17 pm »
- SHMultiFileProperties(Data, 0);
I modified the link in my original post. I fixed my issue by copy pasting again the code from the link to my application and the display of the properties of several files works again

- DoDragDrop(DataObject, Self as IDropSource, DROPEFFECT_COPY, Effect);
I tried the same fix without success, but a clue. Effect seems to be a LPDWORD in Lazarus, so the following lines needs to be corrected :
  Effect: DWORD;
  Effect := DROPEFFECT_NONE;
I try to avoid pointers as much as I can because I always fail to handle them, and it seems to be still the case here. Any help?

Thanks again.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Multiple file properties and Drag and Drop
« Reply #2 on: September 04, 2018, 06:01:01 pm »
- DoDragDrop(DataObject, Self as IDropSource, DROPEFFECT_COPY, Effect);
[...] Effect seems to be a LPDWORD in Lazarus, so the following lines needs to be corrected :
  Effect: DWORD;
  Effect := DROPEFFECT_NONE;
I try to avoid pointers as much as I can because I always fail to handle them, and it seems to be still the case here. Any help?

Thanks again.

Ah ... how about passing Effect as a pointer? i.e. call as:
    DoDragDrop(..., @Effect)
Or is it a callback?
« Last Edit: September 04, 2018, 06:05:39 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

HomeBoy38

  • Jr. Member
  • **
  • Posts: 59
Re: Multiple file properties and Drag and Drop
« Reply #3 on: September 04, 2018, 06:39:10 pm »
I tried this but i got an invalid typecast :(
I do not know about the callback concept (maybe I do some without knowing the terminology)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Multiple file properties and Drag and Drop
« Reply #4 on: September 04, 2018, 06:59:19 pm »
I tried this but i got an invalid typecast :(

Are you sure the parameter Effect is declared as LPDWORD? If so, try something like this:
Code: Pascal  [Select][+][-]
  1. var
  2.   AnEffect: DWORD;
  3.   PEffect: LPDWORD;
  4.  
  5. {... whatever else ...}
  6.  
  7.   Effect := DROPEFFECT_NONE;
  8.   PEffect := @AnEffect; { or PEffect := LPDWORD(@AnEffect) }
  9.   DoDragDrop(DataObject, Sender, PEffect);
  10.  

Quote
I do not know about the callback concept (maybe I do some without knowing the terminology)

Basically, a callback is a function or procedure of your own which is called from some external source; i.e. it's code which is called back from somewhere rather than code that you call yourself. Events, for example, can be cosidered a form of callback.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

HomeBoy38

  • Jr. Member
  • **
  • Posts: 59
Re: Multiple file properties and Drag and Drop
« Reply #5 on: September 04, 2018, 07:39:06 pm »
I have already said thanks? THANKS!

I presume you mean AnEffect := DROPEFFECT_NONE;
I am a bit confused why PEffect := @AnEffect; or PEffect := LPDWORD(@AnEffect); are similar, the second one sound like a pointer of a pointer to me (my nightmare during classes  :o )

Anyway, I made the noob mistake of writing the whole procedure on the same line, more readable to me but making wrong asumptions during debugging, and in my case, the invalid typecast occurs on the Sender parameter, before reaching the Effect one. So before asking for help on this one, I will search a bit on my side first.

You might have helped me on the next issue before I got it.

I will keep posted my results, especially if it can help someone else later on

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Multiple file properties and Drag and Drop
« Reply #6 on: September 04, 2018, 09:14:43 pm »
I presume you mean AnEffect := DROPEFFECT_NONE;
I am a bit confused why PEffect := @AnEffect; or PEffect := LPDWORD(@AnEffect); are similar, the second one sound like a pointer of a pointer to me (my nightmare during classes  :o )

Oops! Yes, AnEffect := DROPEFFECT_NONE; The .. ahem ... effects of copy-pasting too quickly  :)

PEffect := @AnEffect; and PEffect := LPDWORD(@AnEffect) have exactly the same meaning: set PEffect (a pointer) to the @ddress of AnEffect. The second form is just a typecast to make the type of the pointer explicit, which is not really needed in this case.

Quote
[...] before asking for help on this one, I will search a bit on my side first.

Good for you! You know where we are if you don't find the solution by yourself. Wish you luck! :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

HomeBoy38

  • Jr. Member
  • **
  • Posts: 59
Re: Multiple file properties and Drag and Drop
« Reply #7 on: September 04, 2018, 09:22:48 pm »
Conclusion :

SHMultiFileProperties: no change of the source code from the original author posted in the first post, I may have done a copy/paste issue

DoDragDrop:
- followed lucamar's advices (thanks again!):
Code: Pascal  [Select][+][-]
  1.  AnEffect: DWORD;
  2.  PEffect: LPDWORD;
  3.  
  4.    AnEffect := DROPEFFECT_NONE;
  5.    PEffect := LPDWORD(@AnEffect);
  6.    FDropSource := TOLEDropSource.Create;
  7.    DoDragDrop(DataObject, FDropSource, DROPEFFECT_COPY, PEffect);
  8.    FDropSource.Free;
  9.  

- declare:
Code: Pascal  [Select][+][-]
  1.  FDropSource: TOLEDropSource;
  2. where
  3.   TOLEDropSource = class(TInterfacedObject, IDropSource)
  4.     private
  5.       { IDropSource }
  6.       function QueryContinueDrag(fEscapePressed: BOOL; grfKeyState: LongWord): HResult; stdcall;
  7.       function GiveFeedback(dwEffect: LongWord): HResult; stdcall;
  8.     end;
  9.  
Note : I had to change also the type to "LongWord" to make it compile

Drag and Drop from my ListView works both in Windows Explorer and inside applications.

I may leave this thread open a little more because I cannot do it in NotePad or WordPad (this last one says the file - the file name is corrupted showing only a square - is missing) under Windows 10 whereas it works in both XP and Seven. I may try Windows 2016 and do my WindowsUpdate before following up... Stay tuned!

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Multiple file properties and Drag and Drop
« Reply #8 on: September 04, 2018, 10:10:19 pm »
DoDragDrop:
- followed lucamar's advices (thanks again!):
Code: Pascal  [Select][+][-]
  1. [... some code ...]
  2.  

Do it rather like this:

Code: Pascal  [Select][+][-]
  1. var
  2.   AnEffect: DWORD;
  3.   PEffect: LPDWORD;
  4.  
  5. {... more things ...}
  6.  
  7.   AnEffect := DROPEFFECT_NONE;
  8.   // PEffect := LPDWORD(@AnEffect); { typecast *not* needed! }
  9.   PEffect := @AnEffect;
  10.   FDropSource := TOLEDropSource.Create;
  11.   { Use try ... finally to avoid leakscin case of problems }
  12.   try
  13.     DoDragDrop(DataObject, FDropSource, DROPEFFECT_COPY, PEffect);
  14.   finally
  15.     FDropSource.Free;
  16.   end;
  17.  

Quote
[... some more code declaring TOLEDropSource ...]
Note : I had to change also the type to "LongWord" to make it compile

From what type did you change it? If it's implementing the interface, changing the type may have unexpected consequences---although it's a good sign that it compiles.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

HomeBoy38

  • Jr. Member
  • **
  • Posts: 59
Re: Multiple file properties and Drag and Drop
« Reply #9 on: September 04, 2018, 11:17:32 pm »
I modified accordingly to your suggestions, better code never hurts ;)

the declaration I changed was compared to the code I found in the link I posted, maybe it has changed in Lazarus source code since and might explain why it was not working before

but no luck with notepad/wordpad under Windows 10 and 2016. Under 2016, I drag and dropped one txt file in Internet Explorer and it opened the file with notepad, funny as it does not open in Notepad if I drag it directly. I should have some bug somewhere and need to investigate but this might not be the subject here

Thanks again, as it showed me the path

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Multiple file properties and Drag and Drop
« Reply #10 on: September 05, 2018, 12:10:46 am »
Hmm... Can't help you much with Windows 10 as I only have up to XP-SP3 (and those boxes in surgery yet! brrr...). Unlikely as it sounds, may it be that there is some new parameter to set the type of drop or its source or something like that? Or something related to OLE you haven't done? MSDN docs may help you with that; although C-centric they are usually very complete.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

HomeBoy38

  • Jr. Member
  • **
  • Posts: 59
Re: Multiple file properties and Drag and Drop
« Reply #11 on: September 08, 2018, 04:27:21 pm »
I made a silly try : compile my program using 64bits instead of Win32: my drag and drop works now under W10 x64
So now, I just need to maintain both executables

 

TinyPortal © 2005-2018