2007. július 10., kedd

Find the TTabSheet in a pagecontrol, an active control is sitting on


Problem/Question/Abstract:

How to find the TTabSheet in a pagecontrol, an active control is sitting on

Answer:

The forms ActiveControl property points to the active control on the form (if any, it may be Nil under certain circumstances). If you want to find the tabsheet in a pagecontrol, this controls is sitting on, you walk up its parent chain:

var
  ctrl: TWinControl;
begin
  if ActiveControl <> nil then
  begin
    ctrl := ActiveControl.Parent;
    while (ctrl <> nil) and not (ctrl is TTabsheet) do
      ctrl := ctrl.parent;
    if ctrl <> nil then
      {... found the tabsheet, can cast it as TTabsheet( ctrl ) to access
                        its properties}

Nincsenek megjegyzések:

Megjegyzés küldése