Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
More info
Object Inspector FAQ
Object Inspector Home
Delphi Components
See also
Products
Form Designer
Runtime Fusion
Print Suite
Commented Image
Image Editor  new!
Delphi Toys
Ultimate Pack  hot!

FAQs
Form Designer FAQ
Print Suite FAQ
Image Editor FAQ

Links
Software for .NET
Software for VB 6
Delphi Tips & Tricks

Services
Outsourcing
Property editors
Due to Borland's deployment agreements TComponentInspector cannot use the standard property editors, so Greatis Software created its own property editor system. This system is extremely simple in use. To use the new property editor is enough to create the new editor class and handle three TComponentInspector's events - just four steps.

Step 1 - creating the editor class
The PropEdit unit of the Object Inspector kit contains the TPropertyEditor class that is used internally in the TComponentInspector for calling any property editors, so just create your own editor class derived from TPropertyEditor and override just one method - Execute. In this example we create the editor for the string-type property. In the overriden Execute method we just call the InputBox function for the value changing. The initial value is got from the Prop property. This property of TPropertyEditor class contains the edited property and can be used for obtaining any necessary information (see TProperty class). If the user pressed OK in the input box, we change the property value using AsString property. Returned value of the Execute function determines whether TComponentInspector must update the value, so we must return True, if the value was changed.

type
  TStringPropertyEditor = class(TPropertyEditor)
  public
    function Execute: Boolean; override;
  end;

...

function TStringPropertyEditor.Execute: Boolean;
var
  OldValue: string;
begin
  with Prop do
  begin
    OldValue:=AsString;
    AsString:=InputBox((Instance as TComponent).Name,Name,OldValue);
    Result:=AsString<>OldValue;
  end;
end;
Step 2 - showing the dialog button
We have to make TComponentInspector display the dialog button in the edited line, so we have to create the handler for the OngetButtonTypeEvent. As you can see we analyze the current property and show the button if the property has string type.
procedure TMainForm.ComponentInspectorGetButtonType(Sender: TObject;
  TheIndex: Integer; var Value: TButtonType);
begin
  with ComponentInspector do
    if Assigned(Properties[TheIndex]) then
      with Properties[TheIndex] do
        if (TypeKind in [tkString,tkWString,tkLString]) and
          (Value=btNone) then Value:=btDialog;
end;
Step 3 - enabling calling external editor
It is not enough to display the button and we have to allow TComponentInspector to use it for calling the property editor by OmnGetEnableExtrenalEditor event. In this code we allow the external editing for any string type.
procedure TMainForm.ComponentInspectorGetEnableExternalEditor(
  Sender: TObject; TheIndex: Integer; var Value: Boolean);
begin
  with ComponentInspector do
    if Assigned(Properties[TheIndex]) then
      with Properties[TheIndex] do
        Value:=TypeKind in [tkString,tkWString,tkLString];
end;
Step 4 - registering editor class
In this code we assign our editor to the string-type property, but we have to check the default property editor passed by the Value to save the default editor and assign our editor only if no other editor for the selected property.
procedure TMainForm.ComponentInspectorGetEditorClass(Sender: TObject;
  TheIndex: Integer; var Value: TPropertyEditorClass);
begin
  with ComponentInspector do
    if Assigned(Properties[TheIndex]) then
      with Properties[TheIndex] do
        if (TypeKind in [tkString,tkWString,tkLString]) and
          not Assigned(Value) then Value:=TStringPropertyEditor;
end;
There is another way to edit the property value in the external dialog without creating the editor class - just edit it manually in OnCallEditor event. If you choose this way, just use the code below.


Step 4 - alternative way
Call your dialog manually in the OnCallEditor event instead of using property editor class and OnGetEditorClass event.

function TMainForm.ComponentInspectorCallEditor(Sender: TObject;
  TheIndex: Integer; var EnableDefault: Boolean): Boolean;
var
  OldValue: string;
begin
  Result:=False;
  with ComponentInspector do
    if Assigned(Properties[TheIndex]) then
      with Properties[TheIndex] do
        if TypeKind in [tkString,tkWString,tkLString] then
        begin
          EnableDefault:=False;
          OldValue:=AsString;
          AsString:=InputBox(
            ComponentInspector.Instance.Name,
            Name,
            OldValue);
          Result:=AsString<>OldValue;
        end;
end;

Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software