Recent

Author Topic: Form goes Frame - drag and drop file  (Read 364 times)

Nicole

  • Hero Member
  • *****
  • Posts: 1075
Form goes Frame - drag and drop file
« on: March 19, 2025, 01:50:43 pm »
Attached is a demo for drag and drop, taken from the Lazarus installation files.
Unit 2 is not needed, but part of the demo.

What I cannot manage:

1) Hot to run within a FRAME instead of within a form?
If I care to transfer everything from the demo form to my frame, - it just does not work any more. The parent-form does not accept the file.
There will be to change anything with the parent Form1, I suspect, but what?

2) The condition for accepting the file shall not be "checked" of a check box as in the demo, but "is a pdf-file". How to put it?

If you wonder, how the frame becomes part of the from. It takes its place as a tabsheet on a TPageControl.

Code: Pascal  [Select][+][-]
  1.     if Frame_Belege  = nil then begin
  2.        Frame_Belege:=TFrame_Belege.Create(self);
  3.        Frame_Belege.Parent:=TabSheet_Belege;
  4.                                end;


paule32

  • Sr. Member
  • ****
  • Posts: 404
Re: Form goes Frame - drag and drop file
« Reply #1 on: March 19, 2025, 02:44:54 pm »
Hi Nicole,

you can place a TTreeView on your main Application Form.
Then you can read out the currently selected Node of the filled TreeView:

if TreeView1.Selected = nil then exit;
node := TreeView1.Selected;

on the Frame or other Form, you place a OnMouseDown Event and check the global Variable "aktuellerBelege" if it nil.
When it is not nil, you can read the mouse X,Y Position for the Node and place the "Beleg" Component on the Frame.

This can be done by:

// global scope or in class ...
var
  belegt: TMemo;
  mouseX, mouseY: Integer;

// mouse event handler
procedure MouseDown(...);
begin
  mouseX := X;
  mouseY := Y;

  if TreeView1.Selected <> nil then
  BelegCTOR;
end;

procedure BelegCTOR;
begin
  beleg := TMemo.Create(Frame);
  try
    beleg.Parent := Frame;   // important !
    belegt.Top := mouseY;
    belegt.Left := mouseX;
    beleg.Width := 320;
    beleg.Height := 200;
    beleg.Visible := true;
  except
    ShowMessage('Error occured');
  end;
end;
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Nicole

  • Hero Member
  • *****
  • Posts: 1075
Re: Form goes Frame - drag and drop file
« Reply #2 on: March 19, 2025, 03:00:55 pm »
Thank you for your answer.
Do you think, there is a different way? The app is rather huge and I do not want to monitor the mouse by such a tiny element all the time. It only shall take the file about once a week.
Is there a way to enable the thing for the Frame just the same way as in the demo?
It looks that easy in the demo.

paule32

  • Sr. Member
  • ****
  • Posts: 404
Re: Form goes Frame - drag and drop file
« Reply #3 on: March 19, 2025, 03:12:47 pm »
To do this manually - you can use my hints.
To do this autmaically:

- use a TTimer and set the Intervall of it to:  1000 * 60 * 60 * 24 * 5.

1000 are the default for 1 Second

mul 60, you have 1 Minute
mul 60, you have 1 Hour
mul 24, you have 1 Day
mul   5, you have 5 Week-Day's

- then onTimer, you set your procedural steps you want.

This will work until you Application is running.
On some reason it would be better, to programming an Application that checks the Instance oif the Application.
And when this instance is available, you can do the stuff above.

AND: a Bonus: (may it could be setup easier) - Use the Task-Planer (I use it on Windows).
With this Tool you can setup Application's that run in Background.
So, the User seems be not monitored.

HTH - Hope This Helps
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Nicole

  • Hero Member
  • *****
  • Posts: 1075
Re: Form goes Frame - drag and drop file
« Reply #4 on: March 19, 2025, 07:08:08 pm »
Thank you for your answer. Unfortunately I am puzzled.
Why do I need a timer? I thought, I drag the item into the Form / Frame.
I neither want a tree-view, not a timer. I just want to grab the item.

I hoped, somebody would tell me to add a component to my form and done.
To add something VISIBLE to my form would make me unhappy. This would show up above every added frame.

And if it is too hard, I will use an old-fashioned dialog and open it by click.
It is hard?




 

TinyPortal © 2005-2018