Delphi 基于树状视图中选中的项目创建选项卡和框架

Delphi 基于树状视图中选中的项目创建选项卡和框架,delphi,treeview,tframe,tpagecontrol,ttabsheet,Delphi,Treeview,Tframe,Tpagecontrol,Ttabsheet,我的表单上有一个从DB表填充的t视图。该列表当前有22个项目,所有项目都有可选中的复选框 t预览位于一个t表单上,该表单具有一个t页面控件,带有一个预先制作的t表单,所有其他t表单都是动态创建的,并分配给它们 在运行时创建新TTabSheet的当前代码如下所示: procedure TForm1.Button2Click(Sender: TObject); var aTab: TTabSheet; begin aTab := TTabSheet.create(self); aTab.

我的表单上有一个从DB表填充的
t视图
。该列表当前有22个项目,所有项目都有可选中的复选框

t预览
位于一个
t表单
上,该表单具有一个
t页面控件
,带有一个预先制作的
t表单
,所有其他
t表单
都是动态创建的,并分配给它们

在运行时创建新
TTabSheet
的当前代码如下所示:

procedure TForm1.Button2Click(Sender: TObject);
var
  aTab: TTabSheet;
begin
  aTab := TTabSheet.create(self);
  aTab.Name := 'tabProduct_' + IntToStr(PageControl1.PageCount+1);
  aTab.PageControl := PageControl1;
  aTab.Caption := 'Product ' + IntToStr(aTab.PageIndex);
  LoadFrame(aTab.PageIndex);
end;
LoadFrame()
过程的代码为:

procedure TForm1.LoadFrame(const index: integer);
var
  aClassName: string;
  aFrameClass : TFrameClass;
  I: Integer;
begin
  if index >= 50 then
    raise Exception.create('Max product count reached');
  if index >= Length(frames) then
    SetLength(frames, index+1);

  if assigned(frames[curIndex]) then frames[curIndex].hide;

  if not assigned(frames[index]) then
  begin
    if index = 0 then
      aClassname := 'TframeClient' // client
    else
      aClassname := 'TframeProdus'; // anything over pageindex 0 is a product
    aFrameClass := TFrameClass(GetClass(aClassname));
    if not assigned(aFrameClass) then
      raise exception.createfmt('Could not find class %s', [aClassname]);
    frames[index] := aFrameClass.Create(self);
    frames[index].name := 'myframe' + IntToStr(index); // unique name
    frames[index].parent := PageControl1.pages[index];
    frames[index].align := alClient;
  end;
  frames[index].show;
  curIndex := Index;
end;
其他相关代码:

type
  TFrameArray = array of TFrame;

<...>

  private
    { Private declarations }
    curIndex: integer;
    frames: TFrameArray;
    procedure LoadFrame(const index: integer);
  public
    { Public declarations }
  end;

  TFrameClass = class of TFrame;

<...>
类型
TFrameArray=TFrame的数组;
私有的
{私有声明}
curIndex:整数;
帧:TFrameArray;
过程LoadFrame(常量索引:整数);
公众的
{公开声明}
结束;
TFrameClass=TFrame的类;
假设我选中了TreeView中项目1、5和13旁边的复选框


我如何确定并修改
按钮2
代码,以便仅为我在
TTreeView
中检查的项目创建
tAbsheet
及其
TFrame
呢?

同时,我设法找到了这种方法,而且似乎效果很好

procedure TForm1.Button2Click(Sender: TObject);
var
  aTab: TTabSheet;
  i: Integer;
begin
   for i:=1 to TreeView1.Items.Count do
begin
   if TreeView1.Items[i-1].Checked then
    begin
      aTab := TTabSheet.create(self);
      aTab.Name := 'tabProduct_' + IntToStr(PageControl1.PageCount+1);
      aTab.PageControl := PageControl1;
      aTab.Caption := TreeView1.Items.Item[i-1].Text;
      LoadFrame(aTab.PageIndex);
    end;
  end;
end;

与此同时,他设法找到了这种方法,而且似乎效果很好

procedure TForm1.Button2Click(Sender: TObject);
var
  aTab: TTabSheet;
  i: Integer;
begin
   for i:=1 to TreeView1.Items.Count do
begin
   if TreeView1.Items[i-1].Checked then
    begin
      aTab := TTabSheet.create(self);
      aTab.Name := 'tabProduct_' + IntToStr(PageControl1.PageCount+1);
      aTab.PageControl := PageControl1;
      aTab.Caption := TreeView1.Items.Item[i-1].Text;
      LoadFrame(aTab.PageIndex);
    end;
  end;
end;