Y
YNTW
Unregistered / Unconfirmed
GUEST, unregistred user!
自己的组件中使用了ADODataSet,并声明了属性CommandText,CommandType,在属性观察器中怎么使CommandText能象ADODataSet的那样,根据CommandType出现不同的设置方式?(100分)<br />安装后在属性观察器中选择不同的CommandType时,CommandText不会出现根据CommandType出现类似ADODataSet的组合框及文本编辑框等,请高手指点。
unit MyComponent;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Db, ADODB;
type
TMyComponent = class(TComponent)
private
FCommand: TADOCommand;
FDataSet: TADODataSet;
function GetCommandText: WideString;
function GetCommandTimeout: Integer;
function GetCommandType: TCommandType;
procedure SetCommandText(const Value: WideString);
procedure SetCommandTimeout(const Value: Integer);
procedure SetCommandType(const Value: TCommandType);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property CommandText: WideString read GetCommandText write SetCommandText;
property CommandTimeout: Integer read GetCommandTimeout write
SetCommandTimeout default 30;
property CommandType: TCommandType read GetCommandType write SetCommandType
default cmdText;
end;
procedure Register;
implementation
uses
DBConsts, ADOConst;
procedure Register;
begin
RegisterComponents('MyLab', [TMyComponent]);
end;
{ TMyComponent }
constructor TMyComponent.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCommand := TADOCommand.Create(Self);
FDataSet := TADODataSet.Create(Self);
end;
destructor TMyComponent.Destroy;
begin
Destroying;
FDataSet.Close;
FreeAndNil(FCommand);
FreeAndNil(FDataSet);
inherited Destroy;
end;
function TMyComponent.GetCommandText: WideString;
begin
Result := FDataSet.CommandText;
end;
function TMyComponent.GetCommandTimeout: Integer;
begin
if FCommand.CommandTimeout > FDataSet.CommandTimeout then
Result := FCommand.CommandTimeout
else
Result := FDataSet.CommandTimeout;
end;
function TMyComponent.GetCommandType: TCommandType;
begin
Result := FDataSet.CommandType;
end;
procedure TMyComponent.SetCommandText(const Value: WideString);
begin
FDataSet.CommandText := Value;
end;
procedure TMyComponent.SetCommandTimeout(const Value: Integer);
begin
FCommand.CommandTimeout := Value;
FDataSet.CommandTimeout := Value;
end;
procedure TMyComponent.SetCommandType(const Value: TCommandType);
begin
FDataSet.CommandType := Value;
end;
end.
unit MyComponent;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Db, ADODB;
type
TMyComponent = class(TComponent)
private
FCommand: TADOCommand;
FDataSet: TADODataSet;
function GetCommandText: WideString;
function GetCommandTimeout: Integer;
function GetCommandType: TCommandType;
procedure SetCommandText(const Value: WideString);
procedure SetCommandTimeout(const Value: Integer);
procedure SetCommandType(const Value: TCommandType);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property CommandText: WideString read GetCommandText write SetCommandText;
property CommandTimeout: Integer read GetCommandTimeout write
SetCommandTimeout default 30;
property CommandType: TCommandType read GetCommandType write SetCommandType
default cmdText;
end;
procedure Register;
implementation
uses
DBConsts, ADOConst;
procedure Register;
begin
RegisterComponents('MyLab', [TMyComponent]);
end;
{ TMyComponent }
constructor TMyComponent.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCommand := TADOCommand.Create(Self);
FDataSet := TADODataSet.Create(Self);
end;
destructor TMyComponent.Destroy;
begin
Destroying;
FDataSet.Close;
FreeAndNil(FCommand);
FreeAndNil(FDataSet);
inherited Destroy;
end;
function TMyComponent.GetCommandText: WideString;
begin
Result := FDataSet.CommandText;
end;
function TMyComponent.GetCommandTimeout: Integer;
begin
if FCommand.CommandTimeout > FDataSet.CommandTimeout then
Result := FCommand.CommandTimeout
else
Result := FDataSet.CommandTimeout;
end;
function TMyComponent.GetCommandType: TCommandType;
begin
Result := FDataSet.CommandType;
end;
procedure TMyComponent.SetCommandText(const Value: WideString);
begin
FDataSet.CommandText := Value;
end;
procedure TMyComponent.SetCommandTimeout(const Value: Integer);
begin
FCommand.CommandTimeout := Value;
FDataSet.CommandTimeout := Value;
end;
procedure TMyComponent.SetCommandType(const Value: TCommandType);
begin
FDataSet.CommandType := Value;
end;
end.