Forum > LCL

[SOLVED] Strange behavior after a drag and drop

(1/3) > >>

valter.home:
Sorry for the unclear title of the post but i didn't know how to describe the problem in one line.
At runtime in a TScrollBox I create panels which can contain different components.
The panels are created in succession one above the other.
For clarity let's imagine we have Panel1 as the first panel, Panel2 below and then Panel3.
If I iterate the TScrollBox simply

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---for i:=0 to ScrollBox1.ComponentCount-1 dobegin  GetContainer:=ScrollBox1.Components[i] as TPanel;  Memo1.Lines.Add(GetContainer.Name);end;I get the names of the panels in sequence correctly.
Then I perform a Drag by moving the panels to different positions, for example Panel2, Panel3, Panel1.
Using the same code I keep getting Panel1, Panel2, Panel3.
Does this mean that the panels are stored according to the sequence of creation?
Is there a way to read their actual position from first to last?

lucamar:

--- Quote from: valter.home on May 17, 2021, 10:22:25 am ---Does this mean that the panels are stored according to the sequence of creation?
--- End quote ---

Yes.


--- Quote ---Is there a way to read their actual position from first to last?
--- End quote ---

AFAICT, Not in such an easy way; you'll have to read their coordinates and sort them accordingly.

valter.home:
Thanks lucamar.
Too bad but it can be solved as you say by keeping track of the movements.

howardpc:
The attached simple example shows one way to do drag and drop with dynamically created controls.

valter.home:
Thanks for your reply but maybe due to my bad english i got misunderstood.
My difficulty is not to create controls at runtime nor to move them by drag and drop but to read the final position of the controls in sequence starting from the first.
I looked at your code, if I move panel 4 to position 1, panel 1 takes the position of 4. In my case, panel 1 must go down under panel 4.
But this is not the problem because I already do it.
The real problem is that I create for example 5 panels (one on top of the other as in your demo), then I move panel 5 in place of 2 which moves to the third position.
I need to read the position of the panels after any movements, in the mentioned case I should have: 1,5,2,3,4
But if I iterate after moving using:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---for i:= 0 to scrollbox1.ComponentCount-1 do
I always get 1,2,3,4,5 whatever the position of the panels after each move.
In fact, if in your example I add a TButton and a TMemo


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var  i: integer;begin  for i:= 0 to scrollbox1.ComponentCount-1 do  begin    memo1.lines.add(scrollbox1.Components[i].Tag.ToString);  end;end;
then I move panel 5 to position 2 on the screen I see 0,4,2,3,1 but in TMemo I will have 0,1,2,3,4.


Navigation

[0] Message Index

[#] Next page

Go to full version