给你一个例子应该明白了
unit LookUpComboBox;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls,
DB, DBTables;
type
TLookUpComboBox = class(TComboBox)
private
FlpSQL: TStrings;
procedure SetQuery(Value: TStrings);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
property lpSQL: TStrings read FlpSQL write SetQuery;
constructor Create(AOwner: TComponent)
override;
destructor Destroy
override;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('xhw', [TLookUpComboBox]);
end;
{ TLookUpComboBox }
constructor TLookUpComboBox.Create(AOwner: TComponent);
begin
inherited;
FHasAll:=false;
FlpSQL := TStringList.Create
end;
destructor TLookUpComboBox.Destroy;
begin
lpSQL.Free;
inherited;
end;
procedure TLookUpComboBox.SetQuery(Value: TStrings);
begin
if lpSQL.Text <> Value.Text then
begin
lpSQL.BeginUpdate;
try
lpSQL.Assign(Value);
finally
lpSQL.EndUpdate;
end;
end;
end;
end.