创建运行时间TTabItem,firemonkey [英] Create run time TTabItem , firemonkey

查看:149
本文介绍了创建运行时间TTabItem,firemonkey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我需要帮助一个项目。
我有一个例程,它将运行时多个TabItems构造到firemonkey中的页面控件,我想在选项卡上有一个关闭按钮。
新的标签有一个复选框,用于从tabitems的样式器加载关闭按钮。
该页面有一个默认选项卡,在某些按钮内,我正在添加运行时的新选项卡项。
我已经设法应用事件关闭默认标签页,但在运行时创建的选项卡页面中不起作用。任何帮助将不胜感激。

Seems like i need some help with a project. I have a routine , that constructs run time multiple TabItems on to a page control in firemonkey, and i want to have a close button on the tab. The new tab has a checkbox for the close button loading from the styler of the tabitems. The page has a default tab, and within some button, i am adding run time the new tab items. I have managed to apply the event for closing the default tab page, but doesn't work within the run time created tab pages. Any help would be appreciated.

这是运行时tabitems的代码

This is the piece of code for the runtime tabitems

procedure TForm1.Button1Click(Sender: TObject);
var
  t : TTabItem;
  o : TFmxObject;
  i : Integer;
  c : TControl;
begin
  t := TTabItem.Create(pgeControl);

  t.Parent := pgeControl;

  o := FindBinding('imgCloseTabPage');
  if o<>nil then
  begin
    for i := 0 to ComponentCount - 1 do
    begin
      if Components[i] is TCheckBox then
      begin
        TCheckBox(Components[i]).OnClick := CheckBox1Click;
      end;
    end;
  end;

  if pgeControl.TabCount - 1 <= nTab then
  begin
    nTab := nTab + 1;
    t.Index := nTab
  end
  else
  begin
    t.Index := pgeControl.TabCount - 1;
    nTab := pgeControl.TabCount - 1;
  end;
  t.Tag := nTab;

  t.Text := 'Some text...' + ' ' + IntToStr(nTab);
  t.Name := 'tabPatient' + IntToStr(nTab);

  t.Height := 35;
  t.Width := 250;
  t.Margins.Top := 0;
  t.Margins.Left := 0;
  t.Margins.Bottom := 0;
  t.Margins.Right := 0;

  t.Padding.Top := -5;
  t.Padding.Left := 0;
  t.Padding.Bottom := 0;
  t.Padding.Right := 0;

  t.TextAlign := TTextAlign.taLeading;
  t.Width := (Length(t.Text) * 6 ) + 60;
  t.Font.Size := 15;
  t.StyleLookup := 'tabMainStyle1';

  l := TLayout.Create(t);
  l.Parent := t;
  l.Align := TAlignLayout.alClient;
  l.Margins.Top := -5;
  l.Margins.Left := 5;
  l.Margins.Right := 5;
  l.Margins.Bottom := 5;
  l.Padding.Top := 0;
  l.Padding.Left := 0;
  l.Padding.Bottom := 0;
  l.Padding.Right := 0;

  pgeControl.ActiveTab := pgeControl.Tabs[pgeControl.TabCount - 1];
end;


推荐答案

在 >已经应用了自定义样式。目前您在之前将其称为,因此无法找到该对象。另外还有一个错误,当你正在寻找对象。

You shoud call FindBinding after having applyed the custom style. Currently you call this before, so it can't find the object. Additionally there was a mistake when you was looking for the object.

所以把这个

o := t.FindBinding('imgCloseTabPage');
if o<>nil then
begin
  if o is TCheckBox then
    TCheckBox(o).OnClick := CheckBox1Click;
end;

after

t.StyleLookup := 'tabMainStyle1';

,并分配事件。

这篇关于创建运行时间TTabItem,firemonkey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆