?
Solved

Top align problem

Posted on 2004-10-12
10
Medium Priority
?
701 Views
Last Modified: 2010-04-05
I add into my component some buttons. My problem is that I wish to keep the order for alignement.

But1
But2
But3
...

When I create a new button and assign alTop I get:

But3
But2
But1

What to do?
0
Comment
Question by:ginsonic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 7

Expert Comment

by:sftweng
ID: 12287493
Add them in reverse order?
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12287851
No. Up is just a sample. I can add anytime, anyitem. In same time I'm interested how to move the But3 between but1 and but2.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12287896
At design time I've done reordering by switching alignment to alNone, repositioning and then switching back.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:ginsonic
ID: 12287957
I need on runtime!
0
 
LVL 17

Expert Comment

by:mokule
ID: 12288649
Hi,
what do You think about this.

procedure TForm1.Button1Click(Sender: TObject);
begin

Panel2.Align := alNone;
Panel3.Align := alNone;
Panel4.Align := alNone;

Panel2.Top := 0;
Panel3.Top := Panel2.Top+Panel2.Height;
Panel4.Top := Panel3.Top+Panel3.Height;

Panel2.Align := alTop;
Panel3.Align := alTop;
Panel4.Align := alTop;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin

Panel2.Align := alNone;
Panel3.Align := alNone;
Panel4.Align := alNone;

Panel4.Top := 0;
Panel3.Top := Panel4.Top+Panel4.Height;
Panel2.Top := Panel3.Top+Panel3.Height;

Panel4.Align := alTop;
Panel3.Align := alTop;
Panel2.Align := alTop;

end;
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12289991
Nope. This create a flickering.

One solution can be :

NewBut.Top:=MyVcl.Height;
NewBut.Align:=alTop;
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12290634
This may be of some help...

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21058579.html

It concerns hiding/showing, but the idea of setting alNone and moving the panel off form seems to help.

Flicker can be controlled (possibly) with LockWindowUpdate:

LockWindowUpdate(Form.handle);
try
  // realign panels
finally
  LockWindowUpdate(0);
end;
0
 

Expert Comment

by:joncmora
ID: 12296230
var
  LastPos, I: Integer;
  NewButton: TButton;
begin
  NewButton := TButton.Create(Self);  //assuming self is your component and it owns all the components inside it
  NewButton.Visible := False;
  NewButton.Parent := Self;
  LastPos := 0;
  for I := Self.ComponentCount - 2 downto 0 do
  begin
    if Self.Components[I] is TButton then
    begin
      LastPos := TButton(Self.Components[I]).Top + TButton(Self.Components[I]).Height;
      Break;
    end;
  end;
  NewButton.Left := 0;
  NewButton.Top := LastPos;// + 2 {we can add a few more pixels just to make sure the new button is below the last one.};
  NewButton.Visible := True;
  NewButton.Align := alTop;
  NewButton.Caption := IntToStr(Self.ComponentCount);
end;
0
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 2000 total points
ID: 12297071
hi ginsonic, i'd use a simple method:

the top of the new control shoulld be less than the bottom of the control on top, so the simplest way is:

procedure TForm1.AlignAfter(Control, After: TControl); //control is the control in creation, after the top control up the created
begin
   Control.Top := After.top+after.height-1; //to be sure that it's going between
   control.Align := alTop;
end;
now let's say that you have 3 panels with align altop

so

Panel1
Panel2
Panel3
using it as follows

procedure TForm1.Button1Click(Sender: TObject);
var
pnl: TPanel;
begin
pnl := TPanel.Create(self);
pnl.Caption := 'New Panel';
AlignAfter(Pnl,Panel2);
pnl.Parent := self;
end;

the order will be
Panel1
Panel2
New Panel
Panel3

really simply, or not?

F68 ;-)
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12298584
Thanks to all for support!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question