Recent

Author Topic: OnFormDropFile procedure want to use variable TMemo-component  (Read 6628 times)

Elmug

  • Hero Member
  • *****
  • Posts: 849
Hi every one.

Am using OnFormDropFile procedure to load the lines of the dropped file in DBMemo1, and have, there:
DBmemo1.Lines.Insert(0, FileNames);{gets filename of FIRST file of dropped files}

I have the above working OK. However, I would like to have instead of DBMemo1, a variable-name, such that if I have two or more Memo boxes, the procedure would work with any of the Memo boxes.

I have tried some tricks with code, but just can't seem to be able to achieve that.

How to do it?

Thanks!

P.S.:
I have been thinking that perhaps the AllowDropFiles ought to belong to the individual components, and also the procedure OnDropFiles, rather than being only so in the Form.
« Last Edit: July 09, 2012, 11:01:16 am by Elmug »

eny

  • Hero Member
  • *****
  • Posts: 1665
Re: OnFormDropFile procedure want to use variable TMemo-component
« Reply #1 on: July 09, 2012, 11:33:44 am »
I have tried some tricks with code, but just can't seem to be able to achieve that.
What tricks?
Please let us know what you have tried and what didn't work.

Quote
How to do it?
  • Add a form local variable type TMemo named DropTarget
  • For your first memo populate the OnMouseEnter method to register that memo as the drop target ( DropTarget := TMemo(Sender); )
  • For your first memo populate the OnMouseLeave method to clear the drop target ( DropTarget := nil; )
  • For your second (or any other) memo assign the OnMouseEnter event; same method as above (do not create a new method)
  • For your second (or any other) memo assign the OnMouseLeave event; same method  as above (do not create a new method)
  • In the form drop files method use DropTarget to populate with the dropped files (test for nil!)
Job done.
« Last Edit: July 09, 2012, 11:36:08 am by eny »
All posts based on: Win11; stable Lazarus 4_4  (x64) 2026-02-12 (unless specified otherwise...)

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: OnFormDropFile procedure want to use variable TMemo-component
« Reply #2 on: July 09, 2012, 12:57:04 pm »
I have tried some tricks with code, but just can't seem to be able to achieve that.
What tricks?
Please let us know what you have tried and what didn't work.

Quote
How to do it?
  • Add a form local variable type TMemo named DropTarget
  • For your first memo populate the OnMouseEnter method to register that memo as the drop target ( DropTarget := TMemo(Sender); )
  • For your first memo populate the OnMouseLeave method to clear the drop target ( DropTarget := nil; )
  • For your second (or any other) memo assign the OnMouseEnter event; same method as above (do not create a new method)
  • For your second (or any other) memo assign the OnMouseLeave event; same method  as above (do not create a new method)
  • In the form drop files method use DropTarget to populate with the dropped files (test for nil!)
Job done.

Hi Eny,

I tried using a a global string variable gComponentName, like this:
  gComponentName.Lines.Insert(0, FileNames);
Then upon enter the actual memo, it would place the name in the string variable.

BUT I now see that I should instead used a gMemo type memo and use the name property, and likely that would work, using onmouseover to first change the global var tmemo name property.

So I'll try that next, and if that does not work, I will try your suggestion, which is very well detailed, and much appreciated.

Thanks!

Bart

  • Hero Member
  • *****
  • Posts: 5743
    • Bart en Mariska's Webstek
Re: OnFormDropFile procedure want to use variable TMemo-component
« Reply #3 on: July 09, 2012, 01:19:03 pm »
Am using OnFormDropFile procedure to load the lines of the dropped file in DBMemo1, and have, there:
DBmemo1.Lines.Insert(0, FileNames);{gets filename of FIRST file of dropped files}

That doesn't compile:  Error: Incompatible type for arg no. 2: Got "Open Array Of AnsiString", expected "AnsiString"

I have the above working OK. However, I would like to have instead of DBMemo1, a variable-name, such that if I have two or more Memo boxes, the procedure would work with any of the Memo boxes.

As long as you have an algorithm to determine which memo to use this can be done.
For instance you could determine where the mouse is when the files are dropped and determine which memo is at that position.
Or you could open the files in whichever memo is the activecontrol of the form?

Code: [Select]
procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String);
var
  AMemo: TMemo;
begin
  if ActiveControl is TMemo then AMemo := TMemo(ActiveControl)
  else AMemo := Memo1; //default fallback
  AMemo.Lines.Insert(0,Filenames[0]);
end; 

Bart

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: OnFormDropFile procedure want to use variable TMemo-component
« Reply #4 on: July 09, 2012, 01:31:05 pm »
Thanks Bart,

I was not understood of the use of ActiveControl, so I was tryng global variables to detect which was active.

I will surely get it done, with all the good help afforded and appreciated!

Will report back. :)

eny

  • Hero Member
  • *****
  • Posts: 1665
Re: OnFormDropFile procedure want to use variable TMemo-component
« Reply #5 on: July 09, 2012, 01:40:43 pm »
BUT I now see that I should instead used a gMemo type memo and use the name property, and likely that would work, using onmouseover to first change the global var tmemo name property.
This has the (probably undesired) effect that when files are dropped on the form outside any memo, the last memo that was hit by the mouse cursor, receives the files.
So your application might not respond as anticipated.

As long as you have an algorithm to determine which memo to use this can be done.
For instance you could determine where the mouse is when the files are dropped and determine which memo is at that position.
See above.

Quote
Or you could open the files in whichever memo is the activecontrol of the form?
The 'problem' with this is that you first have to click on the target memo and start the drag/drop.

All posts based on: Win11; stable Lazarus 4_4  (x64) 2026-02-12 (unless specified otherwise...)

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: OnFormDropFile procedure want to use variable TMemo-component
« Reply #6 on: July 09, 2012, 01:49:58 pm »
BUT I now see that I should instead used a gMemo type memo and use the name property, and likely that would work, using onmouseover to first change the global var tmemo name property.
This has the (probably undesired) effect that when files are dropped on the form outside any memo, the last memo that was hit by the mouse cursor, receives the files.
So your application might not respond as anticipated.

As long as you have an algorithm to determine which memo to use this can be done.
For instance you could determine where the mouse is when the files are dropped and determine which memo is at that position.
See above.

Quote
Or you could open the files in whichever memo is the activecontrol of the form?
The 'problem' with this is that you first have to click on the target memo and start the drag/drop.

Good points, Eny, all of which I will consider.

Thanks! ;)

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: OnFormDropFile procedure want to use variable TMemo-component
« Reply #7 on: July 12, 2012, 12:30:13 am »
Quote
How to do it?
  • Add a form local variable type TMemo named DropTarget
  • For your first memo populate the OnMouseEnter method to register that memo as the drop target ( DropTarget := TMemo(Sender); )
  • For your first memo populate the OnMouseLeave method to clear the drop target ( DropTarget := nil; )
  • For your second (or any other) memo assign the OnMouseEnter event; same method as above (do not create a new method)
  • For your second (or any other) memo assign the OnMouseLeave event; same method  as above (do not create a new method)
  • In the form drop files method use DropTarget to populate with the dropped files (test for nil!)
Job done.


Hi Eny, and everyone.

Apologize for having stated issue is for TMemo components.

Actually, the need is for TDBMemo components, which unfortunately, don't seem to have the OnMouseEnter event.

However, I tried the TDBMemo available events:
  OnDragOver,
  OnStartDrag
and can not get this to work.

I am using MemoX global var type DBMemo for the FormDropFile event.

Now, for the actual TDBMemo component, have tried its available events (mentioned above) and equate tDBMemo names as follows:
 MemoX.Name := DBMemo1.Name in either of the events that DBMemo1 allows.

The code compiles, but when executed get error external SIGSEGV

I would appreciae help in getting this resolved.

Thanks a lot! :-\

« Last Edit: July 12, 2012, 12:49:16 am by Elmug »

 

TinyPortal © 2005-2018