有一个已经设计好的窗体,被动态创建在另一个窗体的tab页中,创建的个数和tab页的个数相同。tab页的个数也是不定的。
如何能获取每个tab页中该窗体的各个控件的值。
如何能获取每个tab页中该窗体的各个控件的值。
解决方案 »
- setcapture 是开始监控鼠标,那哪个函数是停止监控的?
- StringGrid显示问题!
- 删除表的全部内容后,再添加记录出错 ????????????????
- 如何从3个相关表格中分别查询数据并放入到一个DBGrid中显示?
- 请高手指示,线程中Constructor的具体意义及用途
- 使用线程从远程数据库下载数据的问题
- var ww:TParameters;的问题
- create file 为什么总出错?我是严格按照help来的呀!在线等待
- 有关控制窗口大小的问题。
- 谁愿意说说 EhLiab控件的使用方法吗?
- 高分求高效算法................
- 缺少dxCntner.pas 是怎么回事,急!
i,j,k: integer;
begin
for i:=0 to PageControl1.PageCount-1 do
begin
for j:=0 to PageControl1.Pages[i].ComponentCount-1 do
begin
if PageControl1.Pages[i].Components[j] is TXXForm then
begin
for k:=0 to PageControl1.Pages[i].Components[j].ComponentCount-1 do
begin
//...取Edit框的值
if PageControl1.Pages[i].Components[j].Components[k] is TEdit then
begin
ShowMessage(TEdit(PageControl1.Pages[i].Components[j].Components[k]).Text);
end;
//...取TComboBox框的值
if PageControl1.Pages[i].Components[j].Components[k] is TComboBox then
begin
ShowMessage(TComboBox(PageControl1.Pages[i].Components[j].Components[k]).Text);
end;
//....
end;
end;
end;
end;
end;
begin
TabSheet := TRzTabSheet.Create(Self);
with TabSheet do
begin
PageControl:=RzPageControl2;
Caption:='第'+IntToStr(i)+'个结果集';
Application.CreateForm(TResultForm, ResultForm);
ResultForm.Dock(TabSheet,BoundsRect);
end;
end;
程序中的代码如上,但是按照天行者老大的代码执行PageControl1.Pages[i].ComponentCount这个值是0,怪了,为什么会取不到ResultForm呢
还有一个建议,就是你应该把Form1..Form10都继续同一个父类,把他们共有的信息都放在父类里,这个在TFormList里取出信息的时候,可以统一用其父类进行强制转换.
unit FormList;interfaceuses
Classes, Forms;type
TFormList = class
private
FList: TStrings;
function GetCount: integer;
public
constructor Create;
destructor Destroy; override; function Add(AKey: string; AForm: TForm): Integer;
function Get(AKey: string): TForm; overload;
function Get(AIndex: Integer): TForm; overload;
function IndexOf(AKey: string): Integer;
procedure Delete(AKey: string);
procedure Clear; property Count: Integer read GetCount;
end;implementationconstructor TFormList.Create;
begin
FList := TStringList.Create;
end;destructor TFormList.Destroy;
begin
FList.Free;
inherited;
end;function TFormList.Add(AKey: string; AForm: TForm): Integer;
var
iIndex: Integer;
begin
iIndex := IndexOf(AKey);
if iIndex < 0 then
Result := FList.AddObject(AKey, AForm)
else
begin
FList.Objects[iIndex] := AForm;
Result := iIndex;
end;
end;function TFormList.Get(AKey: string): TForm;
var
iIndex: Integer;
begin
iIndex := IndexOf(AKey);
if iIndex >= 0 then
Result := TForm(FList.Objects[iIndex])
else
Result := nil;
end;function TFormList.Get(AIndex: Integer): TForm;
begin
if (AIndex > -1) and (AIndex < Count) then
Result := TForm(FList.Objects[AIndex])
else
Result := nil;
end;function TFormList.IndexOf(AKey: string): Integer;
begin
Result := FList.IndexOf(AKey);
end;procedure TFormList.Delete(AKey: string);
var
iIndex: Integer;
begin
iIndex := IndexOf(AKey);
if iIndex >= 0 then
FList.Delete(iIndex);
end;procedure TFormList.Clear;
begin
FList.Clear;
end; function TFormList.GetCount: integer;
begin
Result := FList.Count;
end;end.
这种动态创建Form的Parent属于Application,PageControl1.Pages[i].ComponentCount=0是正常,不等于零才是不正常,你应该在动态创建Form的时候,指定Form的Parent是PageControl1.Pages[i]就可以了。
ResultForm.Parent := RzPageControl2.Pages[i-1]//i从1开始
天行者,指定了之后还是一样:PageControl1.Pages[i].ComponentCount=0谢谢suihu,但是总觉得应该有更简单的方法,劳驾天行者再帮偶看看
Application.CreateForm(TResultForm,ResultForm);
我是以一个静态的Page页为例,动态一样。
procedure TForm1.Button1Click(Sender: TObject);
var
fm: TForm2;
i,j,k: integer;
begin
fm := TForm2.Create(PageControl1.Pages[0]);//如果是动态创建的Page,此处应该是动态创建的Page实例
fm.Parent := PageControl1.Pages[0]; //同上
fm.Align := alClient;
for i:=0 to PageControl1.Pages[0].ComponentCount-1 do
begin
for j:=0 to PageControl1.Pages[0].ComponentCount-1 do
begin
if PageControl1.Pages[0].Components[j] is TForm2 then
begin
for k :=0 to PageControl1.Pages[0].Components[j].ComponentCount-1 do
ShowMessage(PageControl1.Pages[0].Components[j].Components[k].Name);
end;
end;
end;
end;