- UID
- 4497
注册时间2005-11-9
阅读权限10
最后登录1970-1-1
周游历练
该用户从未签到
|
发表于 2007-1-27 17:31:57
|
显示全部楼层
原帖由 caterpilla 于 2007-1-26 18:08 发表
用模糊查询?不太理解你的意思。
程序中是一次把所有记录读进来直接处理了,因为字段BH的内容已经体现出了大体层次结构,排序后就已经接近树型了,只要按照层次加到TREEVIEW就可以了。
BH字段如果能在设 ...
你说的有道理
我是这么做的 呵呵!~ 可能是太罗嗦了点
多线程线程代码
unit Unit2;
interface
uses
Classes,SysUtils,ADODB,
ComCtrls;
type
TLoadin = class(TThread)
private
tname:string;
ADOQuery1:TADOQuery;
{ Private declarations }
protected
procedure Execute; override;
public
constructor Create(const tabname:string);
destructor Destroy; override ;
end;
implementation
uses
Unit1;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure Loadin.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ Loadin }
constructor TLoadin.Create(const tabname: string);
begin
tname:=tabname;
ADOQuery1:=TADOQuery.Create(nil);
ADOQuery1.Connection:=Form1.ADOConnection1;
inherited Create(True);
end;
destructor TLoadin.Destroy;
begin
ADOQuery1.Free;
inherited Destroy;
end;
procedure TLoadin.Execute;
var
str,t1,n1:string;
i,j,k,bh:Integer;
Node,root,node1:TTreeNode;
begin
{ Place thread code here }
root:=form1.TreeView1.Items.Add(nil,tname);
for j:=0 to 9 do
begin
for k:=0 to 9 do
begin
t1:=IntToStr(j)+IntToStr(k);
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
str:='SELECT * FROM '+tname+' WHERE bh LIKE ''' + t1 + '%''' ;
ADOQuery1.SQL.Add(str);
ADOQuery1.Open;
ADOQuery1.Sort:= 'bh'+' ASC';
for i:=0 to ADOQuery1.RecordCount -1 do
begin
n1:=ADOQuery1.fieldbyname('cname').AsString;
bh:= ADOQuery1.fieldbyname('bh').AsInteger;
if (bh>0) and (bh<99) then
Node := form1.TreeView1.Items.AddChild(root,IntToStr(bh)+ n1) ;
if ((bh>99) and (bh<99999)) then
Node1 :=form1.TreeView1.Items.AddChild(Node,IntToStr(bh)+n1);
if (bh>99999) then
form1.TreeView1.Items.AddChild(node1,IntToStr(bh)+n1);
ADOQuery1.Next;
end;
end;
end;
end;
end. |
-
-
test.rar
101.45 KB, 下载次数: 2, 下载积分: 飘云币 -2 枚
评分
-
查看全部评分
|