复制Tabsheet @运行时,在编辑过程后读取值 [英] copy a Tabsheet @ run time , read values back after edit process

查看:128
本文介绍了复制Tabsheet @运行时,在编辑过程后读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发现将代码复制到Tpagecontrol的一些编辑表单

I already found that code to copy several instances of an edit form to a Tpagecontrol

var
   aForm : TMyForm;
   tabSheet : TTabSheet;
begin
   //Create a new tab sheet
   tabSheet := TTabSheet.Create(PageControl1) ;
   tabSheet.PageControl := PageControl1;

   //create a form
   aForm := TMyForm.Create(tabSheet) ;
   aForm.Parent := tabSheet;
   aForm.Align := alClient;
   aForm.BorderStyle := bsNone;
   aForm.Visible := true;
   tabSheet.Caption := aForm.Caption;

   //activate the sheet
   PageControl1.ActiveSheet := tabSheet;
end;

假设我运行这个代码3x,我如何读回aForm的任何实例的值。按钮例如第一页/第一页?

Assume I run this code 3x , how do i read back the values of any instance of the aForm.button eg. the first page / first instance ?

推荐答案

最好的方法是保存窗体的实例。目前唯一能够做到这一点的方法是搜索页面控件上的控件。

The best way would be to save an instance of the form. The only way you would be able to do it at the moment would be to search through the controls on the page control.

例如,你可以这样做:

For example, you could do something like this:

function CreateTabAndForm: TMyForm;
var
  tabSheet : TTabSheet;
begin
  //Create a new tab sheet
  tabSheet := TTabSheet.Create(PageControl1) ;
  tabSheet.PageControl := PageControl1;

  //create a form
  Result := TMyForm.Create(tabSheet) ;
  Result.Parent := tabSheet;
  Result.Align := alClient;
  Result.BorderStyle := bsNone;
  Result.Visible := true;
  tabSheet.Caption := Result.Caption;

  //activate the sheet
  PageControl1.ActiveSheet := tabSheet;
end;

然而,您需要注意这种方法,因为如果页面控件的形式可能会被破坏被销毁。

You need to be careful with this approach, however, as the form could get destroyed if the page control is destroyed.

要创建选项卡,您可以执行以下操作:

To create the tabs you would then do something like this:

MyForm1 := CreateTabAndForm;
MyForm2 := CreateTabAndForm;
MyForm3 := CreateTabAndForm;

访问表单上的按钮将是MyForm1.button。

To access a button on the form would be MyForm1.button.

这篇关于复制Tabsheet @运行时,在编辑过程后读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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