TObjectInspector

About TObjectInspector
Overview
Using Bitmasks

Published Properties

AllowDeletes
BitMaskProps
BitMaskTags
ClearCutBufferOnPaste
CutAndPaste
DisplayGrid
EditButtonProps
GridX
GridY
InspectorHeight
InspectorLeft
InspectorTop
InspectorWidth
PropertyDescriptions
ShowDescriptions
SnapToGrid
SupportedProps
UnEditableProps
UnsupportedProps


Published Events

OnBeforeCopy
OnBeforeCut
OnBeforeDelete
OnBeforePaste
OnCreateControl
OnEditButtonClick
OnMenuPopup
OnSelectCell


Public Properties and Methods

Create
Destroy
AlignLeft
AlignTop
CenterHorz
CenterVert
ContinuousAdd
ControlsCut
ControlsCopied
Copy
CreateNewControl
Cut
DeselectAll
DeselectControl
DesignForm
DFM
Execute
FocusInspector
Form
GetPropertyEditMode
GetPropertyName
GetPropertyType
GetPropertyValue
Hide
IndexOfPropertyName
MenuItemWizard
NewControlDFM
PaintGrid
Paste
Preview
PropertyEditMode
PropertyName
PropertyType
PropertyValue
Row
SelectControl
SelectedControls
SetControlProperty
SetPropEditMode
SetPropValue
Show
ShowAlignmentOptions
SpaceEqualHorz
SpaceEqualVert
UpdateBitMaskProps
UpdateEditButtonProps
UpdateInspector
UpdateMainForm
UpdatePropertyDescriptions
UpdateSupportedProps
UpdateUnEditableProps
UpdateUnSupportedProps

 


OVERVIEW

The TObjectInspector is a very powerful component that allows you to make virtually any Delphi form into a user-definable form.  This tool represents both the Object Inspector and the Design Palette for making customizations to forms and it fully encapsulates these features.  The TObjectInspector and the accompanying TDFMMerger and TADODFMMerger components can provide you with the tools that you need to impress your clients with easily customizable forms.

Considerations:
With great power comes great responsibility, so careful deliberation should be undertaken before deciding to make a form user-definable.  If you are allowing users to dramatically alter your form's control sizes and locations, you may eventually run into a conflict.  For example, a user may decide to move a control to an empty location on a form.  A developer may later utilize the empty space for a new control.  The result of merging the DFMs (via the TDFMMerger) would be a form where both controls are located in the same area with one overlapping the other.  While this is not a critical issue (since it can easily be corrected by an end user), it is one worth noting.

The best scenario for allowing users to modify a form is when a form is in a relatively mature state in terms of software development. If you expect to continuously evolve a form over time, that form may not be a good candidate for allowing most (but not all) types of user customizations.

The TObjectInspector can be used to allow end-users to add controls to a form.  However, unless care is taken when implementing this feature set, conflicts can arise.  One technique for providing users with the ability to add controls to forms while avoiding design conflicts is to always place developer designed controls onto a TabSheet of a PageControl.  This way the end-users can be instructed to only add their new controls to new TabSheets that they create (thereby avoiding control positioning conflicts in the developer design space). In other words, developers have their play space, and the end-users have theirs.

As long as your forms are reasonably complete, your experience with allowing users to customize forms will likely be very good.  Just keep in mind that the TObjectInspector provides many options (such as setting the SupportedProperties, UnsupportedProperties, UneditableProperties, and creating Bitmask Tags just to name just a few) for limiting what end-users can and cannot do to your forms and every effort should be made to leverage this power to insure your successful implementation of user-definable forms.



PUBLISHED PROPERTIES


AllowDeletes
 
property AllowDeletes : Boolean;

Description
Set AllowDeletes to False to prevent any controls from being deleted.


BitMaskProps
 
property BitMaskProps: TStrings;

Description
Load BitMaskProps with a list of property names that correspond to a Bitmask setting indicated by a control's tag property. 

For example, add the property 'Color' to the BitMaskProps list. Then set the tag of a control that you do not want the user to edit the color of to an integer that corresponds to a bitmask where color is turned off. 

To build a list of BitMask tags that correspond with your properties, use the BitMask Creator that was included with the components. The BitMaskTags property must be set to True or BitMaskProps will be ignored.

See Also: Using Bitmasks


BitMaskTags
 
property BitMaskTags : Boolean;

Description
Set BitMaskTags to True to use tag values that represent a bitmask of uneditable properties based upon tag settings.

See Also: Using Bitmasks


ClearCutBufferOnPaste
 
property ClearCutBufferOnPaste : Boolean;

Description
Set ClearCutBufferOnPaste to True to clear the controls in the cut buffer when controls are pasted
and prevent any of the controls from being pasted again.


CutAndPaste
 
property CutAndPaste : Boolean;

Description
Set CutAndPaste to False to prevent any controls from being cut.


DisplayGrid
 
property DisplayGrid: Boolean;

Description
Set DisplayGrid to True to display a grid on the form that corresponds to the GridX and GridY settings.


EditButtonProps
 
property EditButtonProps: TStrings;

Description
Load EditButtonProps with a list of property names that will have an ellipse button rather than the standard edit box or combobox.  

Use OnEditbuttonClick to set property values when the ellipse button is pressed. 


GridX
 
property GridX: Integer;

Description
Use GridX to set the X coordinates for the DisplayGrid and SnapToGrid properties.


GridY
 
property GridY: Integer;

Description
Use GridY to set the Y coordinates for the DisplayGrid and SnapToGrid properties.


InspectorHeight
 
property InspectorHeight: Integer;

Description
Use InspectorHeight to set the Height of the Object Inspector form.


InspectorLeft
 
property InspectorLeft: Integer;

Description
Use InspectorLeft to set the Left position of the Object Inspector form.


InspectorTop
 
property InspectorTop: Integer;

Description
Use InspectorTop to set the Top position of the Object Inspector form.


InspectorWidth
 
property InspectorWidth: Integer;

Description
Use InspectorWidth to set the Width of the Object Inspector form.


PropertyDescriptions
 
property PropertyDescriptions: TStrings;

Description
Load PropertyDescriptions with a list of property names and property descriptions for  displaying in the description panel at the bottom of the Object Inspector form.

The PropertyDescriptions entries must be in the form of "Property=Description"

Example: 
with Object1.PropertyDescriptions do
          Add('Color=Specifies the background color of the control.');


ShowDescriptions
 
property ShowDescriptions : Boolean;

Description
Set ShowDescriptions to True to display the property description panel at the bottom of the Object Inspector.


SnapToGrid
 
property SnapToGrid : Boolean;

Description
Set SnapToGrid to True to cause controls to size and move within the GridX and GridY coordinates.


SupportedProps
 
property SupportedProps: TStrings;

Description
Load SupportedProps with a list of property names that represent all of the properties that will be displayed in the Object Inspector grid.

If SupportedProps is left empty, all available properties will be loaded except for those properties specified in the UnSupportedProps list.


UnEditableProps
 
property UnEditableProps: TStrings;

Description
Load UnEditableProps with a list of property names that represent the properties that will be displayed in the Object Inspector grid, but will not be editable. 


UnSupportedProps
 
property UnSupportedProps: TStrings;

Description
Load UnSupportedProps with a list of property names that represent the properties that will not be displayed in the Object Inspector grid. 



PUBLISHED EVENTS


OnBeforeCopy
 
type
   TOnBeforeCopyEvent = procedure (Sender: TObject; var CanCopy: Boolean) of object;

  property OnBeforeCopy: TOnBeforeCopyEvent;


Description
Write an OnBeforeCopy event handler to specify whether the selected controls can be copied into the copy buffer.  Set the CanCopy parameter to False to prevent the controls from being copied.


OnBeforeCut
 
type
    TOnBeforeCutEvent = procedure (Sender: TObject; var CanCut: Boolean) of object;

  property OnBeforeCut: TOnBeforeCutEvent;

Description
Write an OnBeforeCut event handler to specify whether the selected controls can be cut from the form and placed into the cut buffer.  Set the CanCut parameter to False to prevent the controls from being cut.


OnBeforeDelete
 
type
    TOnBeforeDeleteEvent = procedure (Sender: TObject; var CanDelete: Boolean) of object;

  property OnBeforeDelete: TOnBeforeDeleteEvent;

Description
Write an OnBeforeDelete event handler to specify whether the selected controls can be deleted from the form.  Set the CanDelete parameter to False to prevent the controls from being deleted.


OnBeforePaste
 
type
    TOnBeforePasteEvent = procedure (Sender: TObject; var CanPaste: Boolean) of object;

  property OnBeforePaste: TOnBeforePasteEvent;

Description
Write an OnBeforePaste event handler to specify whether the controls in the cut or copy buffer can be pasted onto the form.  Set the CanPaste parameter to False to prevent the controls from being pasted.


OnCreateControl
 
type
  TOnCreateControlEvent = procedure (Sender: TObject; Control: TControl) of object;

  property OnCreateControl: TOnCreateControlEvent;


Description
Write an OnCreateControl event handler to process controls as they are created.  The Control parameter is the newly created control.  The OnCreateControl event is called when controls are pasted onto the Design Form and when controls are added to the form via the CreateNewControl procedure.


OnEditButtonClick
 
property OnEditButtonClick: TNotifyEvent;

Description
Write an OnEditButtonClick event handler to bring up an appropriate list or dialog when the user presses the ellipsis button in a grid cell.  The OnEditButtonClick event handler can set the value of the field based on the user response to the list or dialog. 


OnMenuPopup
 
property OnMenuPopup: TNotifyEvent;

Description
Write an OnMenuPopup event handler to take specific action just before the Design Form's pop-up menu appears. 


OnSelectCell
 
type
    TSelectCellEvent = procedure (Sender: TObject; ACol, ARow: Longint; var CanSelect: Boolean) of object;


property OnSelectCell: TSelectCellEvent;

Description
Write an OnSelectCell event handler to specify whether any particular cell in the grid can be selected.  The Col and Row parameters indicate the column and row indexes of the cell that is   about to be selected. Set the CanSelect parameter to False to prevent the cell being selected.



PUBLIC PROPERTIES AND METHODS


AlignLeft
 
procedure AlignLeft;

Description
Use AlignLeft to align all of the selected controls to the left position of the control that was selected first.


AlignTop
 
procedure AlignTop;

Description
Use AlignTop to align all of the selected controls to the Top position of the control that was selected first.


CenterHorz
 
procedure CenterHorz;

Description
Use CenterHorz to center all of the selected controls along the horizontal axis within the parent window.


CenterVert
 
procedure CenterVert;

Description
Use CenterVert to center all of the selected controls along the vertical axis within the parent window.


ContinuousAdd
 
property ContinuousAdd: Boolean;

Description
Set ContinuousAdd to True to prevent the NewControlDFM property from being cleared after a new control is added to the Design Form.  

If the NewControlDFM property is not empty, a new control will be added to the Design Form each time the Design Form is clicked.


ControlsCut
 
function ControlsCut: Integer;

Description
Read ControlsCut to find out if there are controls in the cut buffer.


ControlsCopied
 
function ControlsCopied: Integer;

Description
Read ControlsCopied to find out if there are controls in the copy buffer.


Copy
 
procedure Copy;

Description
Call Copy to copy definitions of all of the selected controls into the copy buffer.


CreateNewControl
 
function CreateNewControl (AClass: TPersistentClass):String;

Description
Call CreateNewControl to create a new control of the class type specified in the AClass parameter. 

CreateNewControl prepares a DFM for the new control and places the control definition into the NewControlDFM property, but does not actually create the control until the user clicks on the Design Form.

If the class has not already been registered, it will be necessary to register the class before calling CreateNewControl.

Example:

  RegisterClass(TEdit);
  ObjectInspector1.CreateNewControl(TEdit);


Cut
 
procedure Cut;

Description
Call Cut to delete the selected controls from the Design Form and copy their definitions into the cut buffer.


DeselectAll
 
procedure DeselectAll;

Description
Use DeselectAll to deselect all of the Design Form's controls and place the focus onto the Design Form.


DeselectControl
 
procedureDeselectControl(Control : TControl);

Description
Use DeselectControl to deselect the control found in the CTRL parameter.


DesignForm
 
property DesignForm: TForm;

Description
DesignForm is the form that the Object Inspector provides for design your form.  DesignForm is the form that the controls are being manipulated on.

You can read the controls array of the DesignForm just as you would any other form.


DFM
 
property DFM: TStrings;

Description
Read DFM to get the form DFM for the current edited state of the Design Form,


Execute
 
function Execute: Boolean;

Description
Execute initializes the Object Inspector and it's associated forms, returning True when the operation is successful.


FocusInspector
 
procedure FocusInspector;

Description
Use FocusInspector to set the active form to the Object Inspector form.


Form
 
property Form: TForm;

Description
Set Form to provide the Object Inspector with the form that is to be redesigned. 

When the Object Inspector is executed, a new form (the Design Form) of the same class type as Form is created and used for the redesigning.

The Form property must be set before the Object Inspector is executed or an error will occur.


GetPropertyEditMode
 
function GetPropertyEditMode(index : Integer):TPropEditMode;

Description
Use GetPropertyEditMode to find the edit mode of the property in the Object Inspector's property grid located at the row identified by the index parameter.


GetPropertyName
 
function GetPropertyName(index : Integer):String;

Description
Use GetPropertyName to find the property name of the property in the Object Inspector's property grid located at the row identified by the index parameter.


GetPropertyType
 
function GetPropertyType(index : Integer):String;

Description
Use GetPropertyType to find the property type of the property in the Object Inspector's property grid located at the row identified by the index parameter.


GetPropertyValue
 
function GetPropertyValue(index : Integer):String;

Description
Use GetPropertyValue to find the property value of the property in the Object Inspector's property grid located at the row identified by the index parameter.


Hide
 
procedure Hide;

Description
Call Hide to hide the Object Inspector form.


IndexOfPropertyName
 
function IndexOfPropertyName(PropertyName :String):Integer;

Description
Use IndexOfPropertyName to find the property grid row of the property name represented by the PropertyName parameter.


MenuItemWizard
 
function MenuItemWizard:String):TMenuItem;

Description
Use MenuItemWizard to access the Design Form's popup menu's "Wizard" menu item. Write an OnClick event handler for MenuItemWizard or set the visible property of MenuItemWizard to False if it is not to be used.


NewControlDFM
 
property NewControlDFM: String;

Description
Read NewControlDFM to find the object definition of the control that is to be created.  NewControlDFM can be set manually, although it should be done so using great care.  If ContinuousAdd is set to True, NewControlDFM is not cleared when the DesignForm is clicked and the new control is added.  To prevent additional controls from being added when ContinuousAdd is True, set NewControlDFM to an empty string.


PaintGrid
 
procedure PaintGrid;

Description
Use PaintGrid to force a refresh of the Design Form's grid.


Paste
 
procedure Paste;

Description
Call Paste to create and add the controls in the cut or copy buffer to the Design Form.


Preview
 
function Preview: TForm;

Description
Preview returns a form with the same DFM definition as the Design Form.  You are responsible for both showing and freeing the preview form when you call Preview.


PropertyEditMode
 
property PropertyName: TPropEditMode;

Description
Read PropertyEditMode to find the edit mode and write PropertyEditMode to set the edit mode of the property in the selected row of the Object Inspector's property grid.


PropertyName
 
property PropertyName: String;

Description
PropertyName returns the property name of the property in the selected row of the Object Inspector's property grid.


PropertyType
 
property PropertyType: String;

Description
PropertyType returns the property type of the property in the selected row of the Object Inspector's property grid.


PropertyValue
 
property PropertyValue: String;

Description
Read PropertyValue to find the value and write PropertyValue to set the value of the property in the selected row of the Object Inspector's property grid.

PropertyValue causes causes the selected controls and the StretchHandles to update if necessary.


Row
 
property Row: Integer;

Description
Read Row to find the index of the selected row and write Row to set the selected row of the Object Inspector's property grid. 


SelectControl
 
procedure SelectControl(Control : TControl);

Description
Use SelectControl to attach StretchHandles to the control in the Control parameter.


SelectedControls
 
function SelectedControls: TList;

Description
Read SelectedControls to get a list of all of the controls that are attached with StretchHandles.


SetControlProperty
 
function SetControlProperty(Control :TControl; PropertyName, Value: String): Boolean; 

Description
Use SetControlProperty to set a boolean, string, integer, float or enumerated type property on a specific control. The Control parameter is the control to be edited, PropertyName is the name of the property, and value is the string representation of the value that the property is to be set to.

The return value indicates whether or not the control's property was successfully set.

SetControlProperty does not cause the control to be selected or automatically update the Object Inspector's property grid. 


SetPropertyEditMode
 
procedure SetPropertyEditMode (index : Integer; Value: TPropEditMode);

Description
Use SetPropertyEditMode to set the edit mode of the property in the Object Inspector's property grid located at the row identified by the index parameter.


SetPropertyValue
 
function SetPropertyValue (index : Integer; Value: String):Boolean;

Description
Use SetPropertyValue to set the value of the property in the Object Inspector's property grid located at the row identified by the index parameter. The return value indicates whether or not the property was successfully set.

SetPropertyValue causes the selected row in the Object Inspector's property grid to be set to the value of index and automatically causes the selected controls and the StretchHandles to update if necessary.


Show
 
procedure Show;

Description
Call Show to show the Object Inspector's form.


ShowAlignmentOptions
 
procedure ShowAlignmentOptions;

Description
Call ShowAlignmentOptions to show the alignment form. 


SpaceEqualHorz
 
procedure SpaceEqualHorz;

Description
Use SpaceEqualHorz to space all of the selected controls equally along their horizontal axis.


SpaceEqualVert
 
procedure SpaceEqualVert;

Description
Use SpaceEqualVert to space all of the selected controls equally along their vertical axis.


UpdateInspector
 
procedure UpdateInspector;

Description
Call UpdateInspector to force an update of the Object Inspectors's property grid.


UpdateMainForm
 
procedure UpdateMainForm;

Description
Use UpdateMainForm to update the form specified in the Form property to match the state of the Design Form.


UpdateBitMaskProps
 
procedure UpdateBitMaskProps;

Description
Use UpdateBitMaskProps to update the Object Inspector's bitmask property list after changing the BitMaskProps list.


UpdateEditButtonProps
 
procedure UpdateEditButtonProps;

Description
Use UpdateEditButtonPropsto update the Object Inspector's edit button property list after changing the EditButtonProps list.


UpdatePropertyDescriptions
 
procedureUpdatePropertyDescriptions;

Description
Use UpdatePropertyDescriptions to update the descriptions in the Object Inspector's property after changing the PropertyDescriptions list.


UpdateSupportedProps
 
procedure UpdateSupportedProps;

Description
Use UpdateSupportedProps to update the Object Inspector's supported property list after changing the SupportedProps list.


UpdateUnEditableProps
 
procedure UpdateUnEditableProps;

Description
Use UpdateUnEditablePropsto update the Object Inspector's uneditable property list after changing UnEditableProps list.


UpdateUnSupportedProps
 
procedure UpdateUnSupportedProps;

Description
Use UpdateUnsupportedProps to update the Object Inspector's unsupported property list after changing the UnSupportedProps list.