[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.
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]
Registering your Property Editor
Your Finished !! Now you need to Register your Property Editor
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
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;
...
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
