To Dephilai:
你好,首先谢谢你给我的解答,我有点疑惑想请教:
我按你的思路试了一下,代码如下:
procedure Tfm_mainxt.FormShow(Sender: TObject);
var
node:ttreenode;
begin
with datamodule2 do
begin
qrytemp.close;
qrytemp.sql.Clear;
qrytemp.sql.Add('select * from customer order by customerid');
qrytemp.open;
qrytemp.first;
while not qrytemp.eof do
begin
node:=treeview1.Items.add(nil,qrytemp.fieldbyname('customerid').AsString+'@'+qrytemp.fieldbyname('customer_name').AsString);
qryorders.Close;
qryorders.sql.Clear;
qryorders.sql.Add('select * from orders where customerid='''+qrytemp.FieldByName('customerid').AsString+'''order by orderdate''');
qryorders.open;
A:--------------- qryorders.First;//[red]在此处出错![/red]
while not qryorders.Eof do
begin
treeview1.Items.Add(node,
qryorders.fieldbyname('orderdate').AsString);
qryorders.next;
end;
qrytemp.next;
end;
end;
end;
我调试是在上面的A处出错,错误信息为:Missing right quote,缺少右引号,为什么?
既然qryorders.sql.add()的语句都已通过,为何在first中发生错误。请帮我检查一下有
和错误? 另外我自己写的代码如下,结果有很多错误,不知错在那里?
type
PMyRec=^TMyRec;
TMyRec=record
ID:string;
IsExpanded:string;
end;
function TFm_mainxt.BuildTree(var Node:TTreeNode;customerid:integer):TTreeNode;
var
RecPtr
MyRec;
nodetemp:TTreenode;
begin
nodetemp:=Node;
qry_ordtree.Close;
qryorders.SQL.Clear;
qry_orders.SQL.Add('select * from orders where customerid='''+
inttostr(customerid)+'''order by orderdate');
qry_orders.Open;
if (Not qry_orders.IsEmpty) Then
while Not qryorders.Eof do
begin
new(RecPtr);
RecPtr.ID:=qry_ordTree.fieldbyname('customerid').AsString;
RecPtr.IsExpanded:='false';
nodetemp:=treeview1.Items.AddChildObjectFirst(Node,
trim(qry_ordTree.fieldbyname('customer_name').AsString),RecPtr);
nodetemp.ImageIndex:=0;
nodetemp.SelectedIndex:=1;
nodetemp.StateIndex:=0;
end;
result:=nodetemp;
end;
procedure Tfm_mainxt.FormCreate(Sender: TObject);
var
MyNode,nodetemp2:TTreeNode;
RecPtr
MyRec;
begin
MyNode:=nil;
MyNode:=BuildTree(MyNode,0);//创建 根节点
qry_orders.Close;
new(RecPtr);
RecPtr:=MyNode.Data;
RecPtr.IsExpanded:='true';
with datamodule2.qrytemp do
begin
close;
sql.Clear;
sql.Add('select * from customer order by customerid);
prepare;
open;
first;
while not eof do
begin
new(RecPtr);
RecPtr.ID:=FieldByname('customerid').AsString;
RecPtr.IsExpanded:='true';
nodetemp2:=TreeView1.Items.AddChildObject(MyNode,
fieldbyname('customerid').AsString+'@+fieldbyname('customername'),RecPtr);
nodetemp2.ImageIndex:=2;
nodetemp2.SelectedIndex:=1;
nodetemp2.StateIndex:=2;
next;
end;
if not(nodetemp2=nil) then
nodetemp2.MakeVisible;
end;
datamodule2.qrytemp.Close;
end;
end;
我对TTreeview控件的用法不太熟悉,查了一些参考书,发现基本上没有介绍该控件的
知识,不知那位有该部分的文章,请发过来看看,to wdsu@htc.net.cn 谢谢!