Enhancements to the DDJ Component Builder

Source code presented to the Australian Delphi User Group

by Steve Moller

December 1996

Based on DDJ Component Builder by Al Williams - Dec. 1995
Adapted by Steven Moller, CSIRO, Australia.
Email: steven.moller@dbce.csiro.au

Functionality
=============
Generate Object Pascal source code defining an Object or a Component
based on property data entered interactively.
The resulting PAS file includes:
 - The object interface definition and implementation
 - Public or published properties with matching private fields
 - Optional read / write procedures for get/setting private fields
 - Setting defaults
 - Registering the object/installing a component on the toolbar.

  plus methods for:
 - Creating new instances and copies
Option 1: Make Dialog Code
 - Setting up a dialog to edit the objects properties
 - Getting the values back from a dialog
Option 2a: Make Component Streaming Code
 - Streaming the component to/from a file using TComponent ReadComponent methods
Option 2b: Make TacStreamable Code
 - Streaming the object to/from a file using TACStreamable methods
Option 3: Make MultiEdit Code
 - Using one dialog to edit multiple instances of the object

Notes
=====
Option 1: Make Dialog Code - Having produced the PAS file you still need to
create the dialog form in the usual way.  Follow these naming conventions:
  Call the Form 'WidgetForm' if your object is called TWidget
  Call properties of type TList and TStringList xxxxList.  CompBld will
    assume the list contains items of type Txxxx and do the appropriate
    typecasting.
  Name the fields with these prefixes:
          ftEdit : FieldName := 'txt'+ PropName;
          ftCombo : FieldName := 'cbo'+ PropName;
          ftCheck : FieldName := 'chk'+ PropName;
          ftRadio : FieldName := 'opt'+ PropName;
          ftList : FieldName := 'lst'+ PropName;
          ftSpin : FieldName := 'spn'+ PropName;
          ftMemo : FieldName := 'mem'+ PropName;
          ftLabel : FieldName := 'lbl'+ PropName;

Option 2a: If your component descends from TComponent, you can use this option
  to generate code to save and load it from a file.  The methods generated can
  handle TLists and TStringlists of other objects.  i.e. a single "save" on the
  top level object in a multilevel tree object structure will save the whole lot!
  Note: Properties must be declared "Published" to be saved to stream.

Option 2b: Make TACStreamable Code - this uses a streaming method designed
by Alan Ciemian,
  Delphi Informant, Dec.1995  This is more efficient on memory than 2a because the
  extra "baggage" that TComponent brings is not required.  However, all objects
  must have a single ancestor, that descends from TACStreamable. (Read the ref.)

Option 3: Make MultiEdit Code -  The approach used is to allow a temporary object
  to be set up prior to calling the dialog.
  If a property isn't the same in all selected objects, it is set to null in
  the temporary object, using a call to NullIfNotEqual for each selected object.
  After the edit only those fields that are not null are copied back to the
  selected objects, using multiple calls to AssignIfNotNull
  The process is controlled by global function gbEditMultiple and various global
  constants.

  Procedures CreateCopy, EditProperties, NullIfNotEqual and AssignIfNotNull
  may be defined in a common ancestor to allow polymorphic editing.  See example
  in unit acStream.  If you dont need this functionality, they can be made local
  to the object or component.  The common ancestor is of type TBunObject by default.

Changes
=======
Enlarge labels and edit boxes to prevent overflow on 1024x768 small fonts.
Re-install the IniCombo components that had disappeared
Set up to read from compbld2.ini
Add (None) to Toolbar group.  If selected, register a non-visual component
Add Field Type and MakeDialog components.  If MakeDialog is checked write
  procedures to pass property values to fields in a dialog and get them back.
Change name of 'Property Name' field from CProp to PName.
Change from linefeed #10 to carriage return #13 + linefeed #10
Add switch to sort property list.
Add code to support streaming using TacStreamable classes by Alan Ciemian,
  Delphi Informant, Dec.1995
BUG: When you click on another property in the listbox, the IniCombo fields
     PType & FType are not updated, and the property type is changed.
     FIX: Inhibit property OnChange event handler when updating the fields on
          the form using SetValues.
BUG: vals objects in PBox are not freed, on close event.
     FIX: add code to ExitItemClick.
Provide functions for editing multiple instances of object.
Note: If using sets, search & replace "SetofOptions" in generated code with
      actual set name.
TLabel code added. i.e. load data into a TLabel on a dialog
Create and free TList and TStringList properties.
Add TComponent streaming.
** Demo to ADUG
Refer events to ComboExit & ComboKey methods for all IniCombos
Debug TComponent Streaming.
Auto typecasting of list items.

Installation
============
1. Unzip components in COMPBLD2.ZIP
2. Move COMPBLD2.INI to \WINDOWS
3. Backup your COMPLIB.DCL
4. Use Option| Install Components to install INICOMBO into Samples page
5. Open and compile COMPBLD2.DPR

6. You can just run COMPBLD2.EXE, if you don't want to change it!

Run the program to create a new object or component
Test it in the TESTBED.DPR project provided (in TEST.ZIP).
EXAMPLE.ZIP contains a simple project with some components created with
this tool.