WebResponsiveGridPanel insert controls programmatically

  1. a take the Responsive grid panel example from WebCore
  2. there are 4 labels and webedits, at run the labels are correctly allignet right on the begin of their controls
  3. I try to insert some controls programmatically, but the inserted labels are allignet left, see my experimental code below. The question is hove to achieve that inserted controls are in the same position as 4 above original labels.

my experimental code :
procedure TForm1.WebFormCreate(Sender: TObject);
var i: integer; edt: TWebEdit; lbl: TWebLabel;
begin
Self.Innerpanel.BeginUpdate;
for i := 0 to 9 do begin
lbl := TWebLabel.Create(Innerpanel);
lbl.Alignment := taLeftJustify;
lbl.Anchors := ;
lbl.AlignWithMargins := False;
lbl.AutoSize := True;
lbl.Caption := 'neco';
lbl.Layout := tlTop;
//// lbl.Name := 'xxx' + inttostr(i);
lbl.HeightStyle := ssAuto;
lbl.WidthStyle := ssAbsolute;
lbl.HTMLType := tLABELTAG;
// lbl.ElementClassName := lbClass;
lbl.ElementFont := efCss;
lbl.ElementPosition := epAbsolute;
lbl.EllipsisPosition := epNone;
lbl.Enabled := True;
// lbl.Assign(WebLabel1); even these not helps

Self.Innerpanel.AddControl(lbl);
edt := TWebEdit.Create(Innerpanel);
Self.Innerpanel.AddControl(edt);

end;
Self.Innerpanel.EndUpdate;
end;

To make the label right-aligned, it is the code in this demo

WebLabel1.ElementHandle.style.setProperty('float','right');

that is responsible for this.

MANY THANKS works, my test and comments for some (WebCore beginners) reader

procedure TForm1.WebFormCreate(Sender: TObject);
var i: integer; edt: TWebEdit; lbl: TWebLabel;
begin
// these works, label is on the owner component
weblabel4.ElementHandle.style.setProperty('float','right');

Self.Innerpanel.BeginUpdate;
for i := 0 to 4 do begin
lbl := TWebLabel.Create(Innerpanel);
lbl.Caption := 'xxx'+IntToStr(i);

// here: TypeError: Cannot read properties of null (reading 'style')
//   label is not on the owner component
// lbl.ElementHandle.style.setProperty('float','right');

Self.Innerpanel.AddControl(lbl);
edt := TWebEdit.Create(Innerpanel);
Self.Innerpanel.AddControl(edt);

// here WORKS GREAT label is on the owner component
lbl.ElementHandle.style.setProperty('float','right');

end;
Self.Innerpanel.EndUpdate;
end;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.