做一棵与数据库相连的树(20分)

  • 主题发起人 主题发起人 ssh78
  • 开始时间 开始时间
S

ssh78

Unregistered / Unconfirmed
GUEST, unregistred user!
我看了书上的例子,说先要自定义一个结构的数据类型:
type
PMyRecord=^TMYRecord;
TMYRecord=record
ParentNodeID:String;
NodeID:String;
Caption:String;
URL:String;
但是我不知道这一段代码该写在哪里
是不是下面的type中?
unit Unit1;
interface
uses
。。。。
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
end.
 
你可用上www.playicq.com上面下载几个树形例子去看看,有你所需要的!
而我用treeview一般都是去读取数据库中。然后显示,没有用到记录类型的!
 
我做了一个不知道你满意不
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.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
513
import
I
S
回复
0
查看
821
SUNSTONE的Delphi笔记
S
后退
顶部