开发一个控件,控件中自动建立ADOQUERY,想编辑TFIELDS属性,如何做啊???急!!(100分)

  • 主题发起人 主题发起人 wangwei200208
  • 开始时间 开始时间
那就试试我这个吧:

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.
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
848
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部