T
thx1180
Unregistered / Unconfirmed
GUEST, unregistred user!
那就试试我这个吧:
unit MyComponent;
interface
uses
Classes, ADODB, DB, Windows, DsgnIntf, DSDesign, DBReg;
type
TMyComponent = class(TComponent)
private
FADOQuery: TADOQuery;
function GetFields: TFields;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Fields: TFields read GetFields;
end;
TMyComponentEditor = class(TComponentEditor)
protected
function GetDSDesignerClass: TDSDesignerClass; virtual;
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Astar', [TMyComponent]);
RegisterComponentEditor(TMyComponent, TMyComponentEditor);
end;
{ TMyComponent }
constructor TMyComponent.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FADOQuery := TADOQuery.Create(Self);
end;
destructor TMyComponent.Destroy;
begin
FADOQuery.Free;
inherited Destroy;
end;
function TMyComponent.GetFields: TFields;
begin
Result := FADOQuery.Fields;
end;
{ TMyComponentEditor }
procedure TMyComponentEditor.ExecuteVerb(Index: Integer);
begin
if Index = 0 then
ShowFieldsEditor(Designer, TMyComponent(Component).FADOQuery, GetDSDesignerClass);
end;
function TMyComponentEditor.GetDSDesignerClass: TDSDesignerClass;
begin
Result := TDSDesigner;
end;
function TMyComponentEditor.GetVerb(Index: Integer): string;
begin
Result := 'My Component Editor';
end;
function TMyComponentEditor.GetVerbCount: Integer;
begin
Result := 1;
end;
end.
unit MyComponent;
interface
uses
Classes, ADODB, DB, Windows, DsgnIntf, DSDesign, DBReg;
type
TMyComponent = class(TComponent)
private
FADOQuery: TADOQuery;
function GetFields: TFields;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Fields: TFields read GetFields;
end;
TMyComponentEditor = class(TComponentEditor)
protected
function GetDSDesignerClass: TDSDesignerClass; virtual;
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Astar', [TMyComponent]);
RegisterComponentEditor(TMyComponent, TMyComponentEditor);
end;
{ TMyComponent }
constructor TMyComponent.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FADOQuery := TADOQuery.Create(Self);
end;
destructor TMyComponent.Destroy;
begin
FADOQuery.Free;
inherited Destroy;
end;
function TMyComponent.GetFields: TFields;
begin
Result := FADOQuery.Fields;
end;
{ TMyComponentEditor }
procedure TMyComponentEditor.ExecuteVerb(Index: Integer);
begin
if Index = 0 then
ShowFieldsEditor(Designer, TMyComponent(Component).FADOQuery, GetDSDesignerClass);
end;
function TMyComponentEditor.GetDSDesignerClass: TDSDesignerClass;
begin
Result := TDSDesigner;
end;
function TMyComponentEditor.GetVerb(Index: Integer): string;
begin
Result := 'My Component Editor';
end;
function TMyComponentEditor.GetVerbCount: Integer;
begin
Result := 1;
end;
end.