Solved

Top align problem

Posted on 2004-10-12
10
695 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 22

Accepted Solution

by:
Ferruccio Accalai earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi with SQL Natvie Client 15 87
LAN or WAN ? 11 83
How to build JSON File in Delphi 6 3 17
Firemonkey DbLookupComboBox equivalent ? 2 38
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now