unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ConvertEdit;
type
TForm1 = class(TForm)
ConvertEdit1: TConvertEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
List: TStringList;
begin
List := TStringList.Create;
List.Add('aaa=111');
List.Add('bbb=222');
List.Add('ccc=333');
List.Add('ddd=444');
ConvertEdit1.ConstList := List;
List.Free;
end;
end.
unit ConvertEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TConvertEdit = class(TEdit)
private
FConstList: TStrings;
procedure SetConstList(const Value: TStrings);
protected
procedure KeyPress(var Key: Char)
override;
public
constructor Create(AOWner: TComponent)
override;
destructor Destroy
override;
published
property ConstList: TStrings read FConstList write SetConstList;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('WangWei', [TConvertEdit]);
end;
{ TConvertEdit }
constructor TConvertEdit.Create(AOWner: TComponent);
begin
inherited Create(AOWner);
FConstList := TStringList.Create;
end;
destructor TConvertEdit.Destroy;
begin
FConstList.Free;
inherited Destroy;
end;
procedure TConvertEdit.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
if key = #13 then
Text := ConstList.Values[Text]
end;
procedure TConvertEdit.SetConstList(const Value: TStrings);
begin
if Assigned(Value) then
FConstList.Assign(Value);
end;
end.