Получение родительской формы компонента



Автор: VID

{ **** UBPFD *********** by delphibase.endimus.com ****
>> Получение родительской формы компонента

Функция возвращает TForm который является родительской
формой передаваемого в функцию компонента.

Зависимости: classes
Автор:       VID, snap@iwt.ru, ICQ:132234868, Махачкала
Copyright:   VID
Дата:        27 марта 2003 г.
***************************************************** }

function GetParentForm(Component: TComponent): TForm;
var
  C: TComponent;
begin
  Result := nil;
  if Component = nil then
    exit;
  C := Component;
  repeat
    Component := C;
    try
    C := Component.Owner except C := Component;
    end;
  until (C is TForm) or (C = Component);
  if C is TForm then
    Result := C as TForm;
end;

// Пример использования:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(GetParentForm(Sender as TComponent).Name);
end;




Похожие по теме исходники

Расширение компонента TEdit




Copyright © 2004-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте