Jump to content

Client alignment and runtime object creation


Recommended Posts

Hi all,

I'm populating a panel with some components created at runtime, and I can't figure out how their placement on the panel

using client side alignment.

Let's say I have a panel with Layout HBOX, and I want to populate it with and edit on the left and a label on the right.

At design time, it is sufficient to have set the Left property value on the Edit lower than the Left property value on the Label;

but at runtime it doesn't work...

I've tried setting CreationOrder property too, but nothing changes.

This is an example:

procedure TvFrame18200.UniButton1Click(Sender: TObject);
var e: tuniedit;
    l:tunilabel;
begin
  l:=tunilabel.Create(self);
  with l do
    begin
      left:=100;
      createorder:=10;
      caption:='ciao';
      parent:=UniPanel4;

    end;

  e:=tuniedit.Create(self);
  with e do
    begin
      left:=0;
      createorder:=0;
      parent:=UniPanel4;
    end;
end;

The only way to accomplish the desired behaviour is to invert the component creation, but it would complicate coding my application;

it is a limitation to create components in the order they will be placed in a panel.

Anybody could help me ?

Thanks 

Andrea

Link to post
Share on other sites
17 hours ago, arilotta said:

I've tried setting CreationOrder property too, but nothing changes.

Hi,

Can you try this approach for now?

1. MainForm.Script:

function generateSortFn(props) {
    return function (a, b) {
        for (var i = 0; i < props.length; i++) {
            var prop = props[i];
            var name = prop.name;
            var reverse = prop.reverse;
            if (a[name] < b[name])
                return reverse ? 1 : -1;
            if (a[name] > b[name])
                return reverse ? -1 : 1;
        }
        return 0;
    };
};

2. UniPanel.ClientEvents.ExtEvents

function add(sender, component, index, eOpts)
{
    sender.items.items.sort(generateSortFn([{name: 'createorder', reverse: false}]))
}

3. How to use:

procedure TMainForm.UniButton1Click(Sender: TObject);
var e: tuniedit;
    l:tunilabel;
begin
  l:=tunilabel.Create(self);
  with l do
    begin
      left:=100;
      createorder:=10;
      caption:='ciao';
      parent:=UniPanel1;

      // or by some other properties
      JSInterface.JSConfig('createorder', [createorder]);
    end;

  e:=tuniedit.Create(self);
  with e do
    begin
      left:=0;
      createorder:=9;
      parent:=UniPanel1;

      // or by some other properties
      JSInterface.JSConfig('createorder', [createorder]);
    end;
end;

...

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...