Tools APICustom Form Constructors |
|
Open Tools API
|
The tricky part of writing a custom form class is defining the
constructor. You must consider several different situations. First of all, do you need to
load a DFM for your custom form class, or only for the classes that the user will derive
from your class?If you need to load a DFM for your classJust call the inherited If you don't need to load a DFM for your classOverride constructor TMyForm.Create(Owner: TComponent); begin inherited CreateNew(Component); // initialize custom fields, etc., here GlobalNameSpace.BeginWriting; try if (ClassType <> TMyForm) and not (csDesigning in ComponentState) then begin if not InitInheritedComponent(Self, TMyForm) then raise Exception.Create('Oops'); if OldCreateOrder and Assigned(OnCreate) then OnCreate(Self); end; finally GlobalNameSpace.EndWriting; end; end; You probably want to issue a better error message than "Oops." |
Copyright © 1998 Tempest Software, Inc. All rights reserved.