procedure TfrmMain.Button1Click(Sender: TObject);var
MyQuery1,MyQuery2 , MyQuery3,MyQuery4 : TAdoQuery ;
sqlCode1 ,sqlCode2 ,sqlCode3 ,sqlcode4 : string;
strTmp1,strTmp3,strTmp4,strTmp5: string;
RootNode1, subNode1 ,subNode2 , subNode3 : TTreeNode;
P1: PString;
begin
strTmp2 :='';
try
MyQuery1 := TAdoQuery.create(nil);
with MyQuery1 do
begin
Connection := AdoCOn;
if active then close;
sql.clear;
sqlCOde1 := ' set rowcount 0 select distinct department,department_name from run..department '
+ ' where len(department)=3' ;
sql.add(sqlcode1);
open;
if not MyQuery1.IsEmpty then
begin
tv_zb.Items.Clear;
tv_zb.Items.BeginUpdate;
New(P1);
strTmp1 := FieldByname('department_name').AsString ;
strTmp2 := FieldByname('department').AsString ;
RootNode1 := tv_zb.Items.AddObject(Nil, 'strTmp1', p1);
RootNode1.ImageIndex := 19;
MyQuery1.next;
end;
tv_zb.Items.EndUpdate;
end;
except
myQuery1.Free;
end; try
MyQuery2 := TAdoQuery.create(nil);
with MyQuery2 do
begin
Connection := AdoCOn;
if active then close;
sql.clear;
SQLCode2 := ' Select Distinct department, department_name From dun..department'
+ ' Where department Like ' + QuotedStr( StrTmp2 ) + '%'+' And Len( department ) = '
+ ' (Len( StrTmp2 ) + 3 )';
sql.add(sqlcode2);
open;
if not MyQuery2.IsEmpty then
begin
tv_zb.Items.BeginUpdate;
strTmp3 := FieldByname('department_name').AsString ;
strTmp2 := FieldByname('department').AsString ;
subNode1 := tv_zb.Items.AddchildObject(RootNode1, strTmp3,nil);
subNode1.ImageIndex := 19;
MyQuery2.next;
end;
tv_zb.Items.EndUpdate;
end;
except
myQuery2.Free;
end; try
MyQuery3 := TAdoQuery.create(nil);
with MyQuery3 do
begin
Connection := AdoCOn;
if active then close;
sql.clear;
SQLCode2 := ' Select Distinct department, department_Name From run..department'
+ ' Where department Like ' + QuotedStr( StrTmp2 ) + '%'+' And Len( department) = '
+ '( Len( StrTmp2 ) + 3 )';
sql.add(sqlcode3);
open;
if not MyQuery3.IsEmpty then
begin
tv_zb.Items.BeginUpdate;
strTmp4 := FieldByname('department_name').AsString ;
strTmp2 := FieldByname('department').AsString ;
subNode2 := tv_zb.Items.AddchildObject(subNode1, strTmp4,nil);
subNode2.ImageIndex := 19;
MyQuery3.next;
end;
tv_zb.Items.EndUpdate;
end;
except
myQuery3.Free;
end; try
MyQuery3 := TAdoQuery.create(nil);
with MyQuery4 do
begin
Connection := AdoCOn;
if active then close;
sql.clear;
SQLCode2 := ' Select Distinct department, department_Name From run..department'
+ ' Where department Like ' + QuotedStr( StrTmp2 ) + '%'+' And Len(department) = '
+ '( Len( StrTmp2 ) + 3 )';
sql.add(sqlcode4);
open;
if not MyQuery4.IsEmpty then
begin
tv_zb.Items.BeginUpdate;
strTmp5 := FieldByname('department_name').AsString ;
strTmp2 := FieldByname('department').AsString ;
subNode3 := tv_zb.Items.AddchildObject(subNode2, strTmp5,nil);
subNode3.ImageIndex := 19;
MyQuery4.next;
end;
tv_zb.Items.EndUpdate;
end;
except
myQuery4.Free;
end;end;
其中strTmp2为全局变量!
为什么可以编译通过而不生成树
我是刚学不久的,以前从来没有建过树,请各位大侠帮帮我啊!万分感谢!
MyQuery1,MyQuery2 , MyQuery3,MyQuery4 : TAdoQuery ;
sqlCode1 ,sqlCode2 ,sqlCode3 ,sqlcode4 : string;
strTmp1,strTmp3,strTmp4,strTmp5: string;
RootNode1, subNode1 ,subNode2 , subNode3 : TTreeNode;
P1: PString;
begin
strTmp2 :='';
try
MyQuery1 := TAdoQuery.create(nil);
with MyQuery1 do
begin
Connection := AdoCOn;
if active then close;
sql.clear;
sqlCOde1 := ' set rowcount 0 select distinct department,department_name from run..department '
+ ' where len(department)=3' ;
sql.add(sqlcode1);
open;
if not MyQuery1.IsEmpty then
begin
tv_zb.Items.Clear;
tv_zb.Items.BeginUpdate;
New(P1);
strTmp1 := FieldByname('department_name').AsString ;
strTmp2 := FieldByname('department').AsString ;
RootNode1 := tv_zb.Items.AddObject(Nil, 'strTmp1', p1);
RootNode1.ImageIndex := 19;
MyQuery1.next;
end;
tv_zb.Items.EndUpdate;
end;
except
myQuery1.Free;
end; try
MyQuery2 := TAdoQuery.create(nil);
with MyQuery2 do
begin
Connection := AdoCOn;
if active then close;
sql.clear;
SQLCode2 := ' Select Distinct department, department_name From dun..department'
+ ' Where department Like ' + QuotedStr( StrTmp2 ) + '%'+' And Len( department ) = '
+ ' (Len( StrTmp2 ) + 3 )';
sql.add(sqlcode2);
open;
if not MyQuery2.IsEmpty then
begin
tv_zb.Items.BeginUpdate;
strTmp3 := FieldByname('department_name').AsString ;
strTmp2 := FieldByname('department').AsString ;
subNode1 := tv_zb.Items.AddchildObject(RootNode1, strTmp3,nil);
subNode1.ImageIndex := 19;
MyQuery2.next;
end;
tv_zb.Items.EndUpdate;
end;
except
myQuery2.Free;
end; try
MyQuery3 := TAdoQuery.create(nil);
with MyQuery3 do
begin
Connection := AdoCOn;
if active then close;
sql.clear;
SQLCode2 := ' Select Distinct department, department_Name From run..department'
+ ' Where department Like ' + QuotedStr( StrTmp2 ) + '%'+' And Len( department) = '
+ '( Len( StrTmp2 ) + 3 )';
sql.add(sqlcode3);
open;
if not MyQuery3.IsEmpty then
begin
tv_zb.Items.BeginUpdate;
strTmp4 := FieldByname('department_name').AsString ;
strTmp2 := FieldByname('department').AsString ;
subNode2 := tv_zb.Items.AddchildObject(subNode1, strTmp4,nil);
subNode2.ImageIndex := 19;
MyQuery3.next;
end;
tv_zb.Items.EndUpdate;
end;
except
myQuery3.Free;
end; try
MyQuery3 := TAdoQuery.create(nil);
with MyQuery4 do
begin
Connection := AdoCOn;
if active then close;
sql.clear;
SQLCode2 := ' Select Distinct department, department_Name From run..department'
+ ' Where department Like ' + QuotedStr( StrTmp2 ) + '%'+' And Len(department) = '
+ '( Len( StrTmp2 ) + 3 )';
sql.add(sqlcode4);
open;
if not MyQuery4.IsEmpty then
begin
tv_zb.Items.BeginUpdate;
strTmp5 := FieldByname('department_name').AsString ;
strTmp2 := FieldByname('department').AsString ;
subNode3 := tv_zb.Items.AddchildObject(subNode2, strTmp5,nil);
subNode3.ImageIndex := 19;
MyQuery4.next;
end;
tv_zb.Items.EndUpdate;
end;
except
myQuery4.Free;
end;end;
其中strTmp2为全局变量!
为什么可以编译通过而不生成树
我是刚学不久的,以前从来没有建过树,请各位大侠帮帮我啊!万分感谢!
解决方案 »
- 低级鼠标键盘钩子的疑问。
- 一个关于listbox的问题
- 我晕。AdoQuery查询出错:Cannot perform this operation on a closed dataset;
- ReportBuilder问题!
- 在线等,调试通过即结贴
- 请用过"ExpressQuantumGrid 4.2 For Delphi 6"的高手解决一下这个问题。给100分
- 关于ReadProcessMemory!
- 三层结构问题:将两个有50万条记录的表建立关联,使ID=Master_ID,请问如何写SQL查询语句速度会加快??
- HELP!!!前端通过SQL语句插入记录的日期型字段问题?
- 这到底是怎么回事,怎么解决啊,不能运行,我一步都前进不了,快啊!
- DBGrid如何获取点击的行的行号?在线等
- 请问如何吧C:\DOCUME~1\转换成完整路径?
第四个try中写错了一个
MyQuery3 := TAdoQuery.create(nil);
应该是MyQuery4 := TAdoQuery.create(nil);
第三和四中的
SQLCode2 := ' Select Distinct ....
改为
SQLCode3 := ' Select Distinct ....
SQLCode4 := ' Select Distinct ....
拜托,楼主,以后自己先检查一下再到这来问!
改为 +'( Len( '''+StrTmp2 +''') + 3 )'