Examples Delphi

The following code demonstrates how to use create a combo box property editor.
Tested using Delphi 5
unit ComboTest;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, DsgnIntf;
type
TEditList = class(TEdit)
private
FListValue: string;
published
property ListValue: string read FListValue write FListValue;
end;
procedure Register;
implementation
type
TTextProperty = class(TPropertyEditor)
private
FList: TStringList;
public
constructor Create(const ADesigner: IFormDesigner;
APropCount: Integer); override;
destructor Destroy; override;
function GetValue: string; override;
procedure SetValue(const Value: string); override;
procedure GetValues(Proc: TGetStrProc); override;
function GetAttributes: TPropertyAttributes; override;
end;
procedure Register;
begin
RegisterComponents('Samples', [TEditList]);
RegisterPropertyEditor(TypeInfo(string), TEditList,
'ListValue', TTextProperty);
end;
{ TSList }
constructor TTextProperty.Create(const ADesigner: IFormDesigner;
APropCount: Integer);
begin
inherited Create(ADesigner, APropCount);
FList := TStringList.Create;
try
FList.LoadFromFile('c:\customstrings.txt');
except
FList.Add('Item 1');
FList.Add('Item 2');
end;
end;
destructor TTextProperty.Destroy;
begin
FList.SaveToFile('c:\customstrings.txt');
FList.Free;
inherited Destroy;
end;
function TTextProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paSortList];
end;
function TTextProperty.GetValue: string;
begin
Result := (GetComponent(0) as TEditList).ListValue;
end;
procedure TTextProperty.GetValues(Proc: TGetStrProc);
var
I: Longint;
begin
for I := 0 to FList.Count -1 do
Proc(FList.Strings[I]);
end;
procedure TTextProperty.SetValue(const Value: string);
begin
(GetComponent(0) as TEditList).ListValue := Value;
if FList.IndexOf(Value) = -1 then
FList.Add(Value);
end;
end.