LMD DesignPack Guide


Using Designer Components


Let's review a scenario for setting up a typical user interface design environment. It should include the following components:

 

Root component - a designable surface where components can be laid out;

Components palette, which supports selection of types of components to be added;

TLMDDesigner providing necessary design functionality;

TLMDPropertyInspector which facilitates viewing and editing of components' properties;

TLMDObjectComboBox which supports quick and convenient selection of components;

TLMDDesignModule which is required for correct interoperability of the LMD-DesignPack components;

TLMDDesignObjects collections which represents the full set of created component and the set of currently selected components in the design environment and facilitates coherent and consistent functionality of LMD-DesignPack components.

 

The following main steps are to be performed to create a basic design environment:

 

1.Create a root component MyRoot (a form or a TWinControl descendant) as described in Root control topic; if MyRoot is not a form, create a TLMDDesignPanel control LMDDesignPanel1;

2.Add two TLMDDesignObjects components: SelectionObjects and AllObjects;

3.Add a TLMDModule component LMDModule1; Root property of LMDModule1 is to be set to MyRoot in the run-time of the application, e.g. see step 9;

4.Add a TLMDDesigner component LMDDesigner1; set its Module property to LMDModule1, Selection property - to SelectionObjects and AllComponents property - to AllObjects; if MyRoot is not a form, set DesignPanel property to LMDDesignPanel1;

5.Add a TLMDPropertyInspector component LMDPropertyInspector1; set as desired its properties which control visual appearance and functionality; in particular, to enable or disable working with events and/or read-only properties set PropKinds property to appropriate values; set its Module property to LMDModule1, Selection property - to SelectionObjects;

6.Add a TLMDObjectComboBox component LMDObjectComboBox1; set its ListObjects property to AllObjects, Selection property - to SelectionObjects;

7.Create components palette representing required component types using standard VCL, LMD or third-party controls, e.g. toolbars, buttons, panels etc;

8.Write the LMDDesigner1.OnComponentInserting event handler to supply an appropriate type of component to be created (assign the AComponentClass parameter); it would typically depend on the state of the components palette, e.g

 

procedure TForm1.LMDDesigner1ComponentInserting(Sender: TObject;
  var AComponentClass: TComponentClass);
begin
  ...
  if EditComponentButton.Pressed then
    AComponentClass := TButton
  else
  ...
end;

 

9.Create some component (e.g. button, checkbox etc) to switch between the design-time and run-time modes; its event handler would typically trigger Active property of LMDDesigner1 and ensure correct assignment of LMDModule1.Root property (to be set to MyRoot), e.g

 

if RunCheckBox.Checked then
begin
  if not LMDDesigner1.Active then
  begin
    ...
    LMDModule1.Root := MyRoot;
    LMDDesigner1.Active := True;
    ...
  end;
end
else
begin
  ...
  LMDDesigner1.Active := False;
  ...
end;

 

This will result in the design environment which supports designing in MyRoot client area, including controlling properties of components via LMDPropertyInspector1 and selecting components via LMDObjectComboBox1. Examples of setups similar to this walk-through you can find in demos located in Demos\Delphi\FormsDesigner, Demos\Delphi\TLMDDesigner etc.