简体   繁体   English

Delphi在页面控件中按标签号显示框架

[英]Delphi display a frame by tag number in page control

I have a unique question. 我有一个独特的问题。 I am using Delphi 2007 on Windows XP. 我在Windows XP上使用Delphi 2007。 I have a form with a TPageControl component. 我有一个带有TPageControl组件的表单。 I created a Frame that I want to display within that PageControl. 我创建了一个要显示在该PageControl中的框架。 I will be creating many other frames that will be displayed based on button click events. 我将创建许多其他框架,这些框架将基于按钮单击事件显示。 Is there anyway to use the tag property of the frame so that when the button is pressed the tag number can be passed into a generic function or procedure so that the functions or procedures can be reused for all the buttons. 无论如何,是否有使用框架的tag属性的功能,以便在按下按钮时可以将标签号传递到通用函数或过程中,以便所有按钮可以复用这些函数或过程。 Another idea was to use the tabsheets index property and match it to the frame tag number. 另一个想法是使用tabsheets索引属性,并将其与框架标签号匹配。 Any suggestions would be great. 任何建议都很好。 Thanks in advance. 提前致谢。

You need an function which maps the tag number to the frame class, something like following: 您需要一个将标签号映射到框架类的函数,如下所示:

type
  TFrameClass = class of TFrame;

function GetFrameClass(const aClassID: Integer): TFrameClass;
begin
  case aClassID of
    1 : Result := TFrameFoo;
    2 : Result := TFrameBar;
    else Result := nil;
  end;
end;

and then you can create frames: 然后您可以创建框架:

var FrClass: TFrameClass;
    Frame: TFrame;
begin
  FrClass := GetFrameClass(btn.Tag);
  if(FrClass <> nil)then begin
     Frame := FrClass.Create(tabsheet);
     Frame.Parent := tabsheet;
  end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM