我做了一个不知道你满意不
unit DBTreeView;
interface
uses
Windows, Messages, SysUtils,Forms, Classes, DB,ADODB,Controls,Dialogs, ComCtrls;
type
TDBTreeView = class(TTreeView)
private
FDataSrc:TDataSource;
FSql_Str:TStrings;
FConnectStr:WideString;
FField:string;
FActive: boolean;
procedure SetConnectionStr(value: WideString);
procedure SetDataSrc(value:TDataSource);
procedure SetSql_Str(value:TStrings);
procedure SetField(value:string);
procedure SetActive(value:boolean);
//procedure SetConnection(value :TAdoconnection);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
FQry:Tadoquery;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property DataField: string read FField write SetField;
property DataSource:TDataSource read FDataSrc write SetDataSrc;
property Sql:TStrings read FSql_Str write SetSql_Str;
property ConnectionString:WideString read FConnectStr write SetConnectionStr;
//property Connection:TAdoconnection write SetConnection;
property Active:boolean read FActive write SetActive;
end;
procedure SetconnectString(var re_str:WideString);
procedure Register;
implementation
procedure SetconnectString(var re_str:WideString);
begin
re_str:= PromptDataSource(application.handle,re_str);
end;
procedure Register;
begin
RegisterComponents('syz_component', [TDBTreeView]);
end;
{ TDBTreeView }
constructor TDBTreeView.Create(AOwner: TComponent);
begin
inherited create(Aowner);
FQry:=TAdoquery.Create(nil);
FDataSrc:=TDataSource.Create(nil);
FSql_Str := TStringList.Create;
FActive:=False;
FQry.ConnectionString:=ConnectionString;
end;
destructor TDBTreeView.Destroy;
begin
FDataSrc.Free;
FQry.Free;
FSql_Str.Free;
inherited;
end;
procedure TDBTreeView.SetActive(value: boolean);
begin
FActive:=value;
if FActive then
begin
FQry.Close;
FQry.SQL.Clear;
FQry.SQL:=FSql_Str;
FQry.Open;
FDataSrc.DataSet:=FQry;
end
else
begin
FQry.Close;
end;
end;
{
procedure TDBTreeView.SetConnection(value:TAdoconnection);
begin
FConnectStr:='';
FQry.Connection:=value;
end;
}
procedure TDBTreeView.SetConnectionStr(value: WideString);
var
str:WideString;
begin
if ConnectionString<>value then
begin
SetconnectString(str);
FConnectStr:=str;
FQry.ConnectionString:=str;
end;
end;
procedure TDBTreeView.SetDataSrc(value: TDataSource);
begin
FDataSrc:=value;
end;
procedure TDBTreeView.SetField(value: string);
begin
FField:=value;
end;
procedure TDBTreeView.SetSql_Str(value: TStrings);
begin
FSql_Str.Assign(Value);
end;
end.