2010. január 31., vasárnap

Inherit forms


How to inherit forms


Insert the following in the OnCreate event of the descendant form:

procedure TForm1.FormCreate(Sender: TObject);
  DummyForm: TForm0; {Ancestor form}
  f: integer;
  tempComp: TComponent;
    DummyForm := TForm0.Create(Application);
    for f := DummyForm.ComponentCount - 1 downto 0 do
      {See if the component exists in the descendant form}
      tempComp := FindComponent(DummyForm.Components[f].Name);
      if not Assigned(tempComp) then
        {Doesn't exist so move it}
        tempComp := DummyForm.Components[f];
        if tempComp is TControl then
          with tempComp as TControl do
            if Parent = DummyForm then
              Parent := Self;
    {Override form properties here}
    {WriteComponentsResFile('unit.dfm, Self)}- - - > {Uncommenting this will update
                the dfm file for the descentant form. Closing and then opening the form unit
                will allow you to edit the inherited components visually}

where TForm0 is the ancestor form.

If you wish to override a number of properties for any component, cut and paste the component in the dfm file. This will allow you to visually edit it.

Nincsenek megjegyzések:

Megjegyzés küldése