[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
ComboListEditor
Welcome to Component Writer's Help - Editors

Filling a combo box for your property at design time!


Hint: When writing your editors, write them in a separate file (example MyEditors.pas). That way, you will not need to include them in your applications (uses clause) each time you want to use your custom components.


Let's say you have a component called MyComponent which has a property KeyField of type TMyField. You would like to be able to have a combo box that enables you to choose from a list of fieldnames (like the Data Controls components)!

Well, you need to create Property Editor !.




First, create a new custom property editor that comes from the inherited class TStringProperty (unit DesignEditors, DesignIntf). Then you need to override theses 2 methods :

function GetAttributes: TPropertyAttributes

This function returns the type of property editor you wish to have. For our example, we return the value [paValueList]. This will show a combo box button for our property in the property inspector.

procedure GetValues(Proc: TGetStrProc)

This procedure will use the Proc passed by param to fill our combo box.

type
  TMyFieldProperty = class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValues(Proc: TGetStrProc); override;
  end;





Now, here is the code to make things happen.

Please note that this is just an example and much more care needs to be put if you are going to check the fields of a Dataset. [/italic]

function TMyFieldProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList]; 
end;
procedure TMyFieldProperty.GetValues(Proc: TGetStrProc);
var
  loPersistent: TPersistent;
begin
  inherited;
  try
    if Self.PropCount = 1
    then begin
      loPersistent := Self.GetComponent(0);
      if loPersistent is TMyComponent
      then begin
        with TMyComponent(loPersistent).DataSource.Dataset do 
        begin
          if not Active then Active := true; 
          for liC := 0 to FieldCount - 1 do
            Proc(Fields[liC].Fieldname);
        end;
      end;
    end;    
  except
  end;
end;





Registering your Property Editor

Your Finished !! Now you need to Register your Property Editor

...
procedure Register
implementation
procedure Register;
begin
  RegisterComponents('Standard', [TMyComponent]);
  RegisterPropertyEditor(TypeInfo(TMyField), TMyComponent, '', TMyFieldProperty);
end;
...




last edited (March 28, 2005) by Tief, Number of views: 2361, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.