Gia*_*rmo 1 windows delphi tpagecontrol delphi-xe2
如何获取有对象的页面编号?例如:第一页上有一个Button1,第二页上有Button2,如何获得没有ActivePageIndex的Button1页面的编号?谢谢.
想要找到特定类的最近父级是很常见的.因此,它可以为实现这一目标而付出代价.
function GetParentWithClass(Control: TControl;
ClassType: TWinControlClass): TWinControl;
begin
Result := Control.Parent;
while Assigned(Result) and not (Result is ClassType) do
Result := Result.Parent;
end;
Run Code Online (Sandbox Code Playgroud)
一旦你有了这个,你可以用它来解决你当前的问题.
var
PageIndex: Integer;
TabSheet: TTabSheet;
.....
TabSheet := GetParentWithClass(Control, TTabSheet) as TTabSheet;
PageIndex := TabSheet.PageIndex;
Run Code Online (Sandbox Code Playgroud)
分离出这样的问题后,您可以GetParentWithClass在其他设置中使用.