Author: Tomas Rutkauskas
I have a component that is used both on an Active Form and on a normal TForm. The
component needs to find out if the application it's being used in is an ActiveX
project or a normal project. Is there a good way to find out?
Answer:
In case your component is TControl you can use the functions below:
1 2 function IsParentFormActiveXOne(Control: TControl): Boolean;
3 function GetParentForm(Control: TControl): TCustomForm;
4 5 function GetParentForm(Control: TControl): TCustomForm;
6 begin7 Result := nil;
8 if Assigned(Control) then9 if Control is TCustomForm then10 begin11 Result := Control as TCustomForm;
12 if Assigned(Result) and (Result is TForm) and13 (TForm(Result).FormStyle = fsMDIForm) then14 begin15 Exit;
16 end;
17 end18 else19 begin20 if Assigned(Control.Parent) then21 Result := GetParentForm(Control.Parent);
22 end;
23 end;
24 25 function IsParentFormActiveXOne(Control: TControl): Boolean;
26 var27 Form: TCustomForm;
28 begin29 Form := GetParentForm(Control);
30 Result := Assigned(Form) and (Form is TCustomActiveForm);
31 end;
32 33 //Otherwise simply use:34 35 if TCustomForm(Owner) is TCustomActiveForm then36 { ... }