怎么没人呀
我知道我说得太抽象了,没办法只好硬着头皮贴出代码
不过它实在是太乱太白痴了,看过请不要笑我
另:如果彻底解决了这问题,再加50分
procedure TForm1.FormCreate(Sender: TObject);
var dri:integer; captionpath
char; nodeadded:ttreenode;
begin
for dri:=65 to 90 do
begin
if getdrivetype(pchar(chr(dri)+':/')) in [3..4]
then begin
captionpath:=pchar(string(chr(dri)+':'));
nodeadded:=treeview1.Items.AddChildobject(treeview1.items[0],chr(dri)+':',captionpath);
nodeadded.HasChildren:=true;
listview1.Items.Add.caption:=chr(dri)+':';
end;
end;
listview1.Items[0].Selected:=true;// 如果在此showmessage(captionpath),得到结果是正确的
end;//这段程序将固定驱动器和网络驱动器加到treeview1里面
procedure TForm1.TreeView1DblClick(Sender: TObject);
var
nodetext,path,entirename:string;
found:integer;
searchrec:tsearchrec;
node,nodewhichisadd,nodeexam:ttreenode;
clearedlist:boolean;
begin
clearedlist:=false; //刚开始还没有clear过
node:=treeview1.selected; //设置node为当前选择的节点
nodetext:=treeview1.selected.Text; //设置nodetext为当前节点的显示文本
nodeexam:=node;
while nodeexam.parent<>nil do nodeexam:=nodeexam.Parent; //防止非本机节点执行事件
if ((nodetext<>'我的电脑') and (not node.expanded) and (nodeexam.text='我的电脑')) then
begin
path:=pchar(node.data)+'/*.*'; //查找对象为当前节点下的所有文件
showmessage(pchar(node.data));//这里出现了问题,如果双击c:,showmessage
//的内容是'd:',双击d:,则showmessage的是'e:',但刚才在formcreate里
//showmesssage都是正确的呀!!!!!!!!!
found:=findfirst(path,faanyfile,searchrec);//查找第一个文件
while found=0 do
begin
if ((searchrec.attr=fadirectory) and (searchrec.name<>'.') and (searchrec.name<>'..')) then
begin
if node.parent.text<>'我的电脑' //设置entirename为当前找到节点绝对路径名
then entirename:=pchar(node.data)+'/'+searchrec.Name; {showmessage(node.Text); }
nodewhichisadd:=treeview1.Items.AddChildObject(node,searchrec.name,pchar(entirename));
//加到当前节点下
nodewhichisadd.HasChildren:=true; //使每个节点前都有+号
if not clearedlist then //判断listview是否clear过了
begin
listview1.Items.BeginUpdate;
listview1.items.Clear;
clearedlist:=true;
listview1.items.EndUpdate;
end;
listview1.Items.Add.caption:=searchrec.name;
end
else begin //如果不是目录文件(是其他文件)则只加到listview下
if not clearedlist then
begin
listview1.items.Clear;
clearedlist:=true;
end;
listview1.Items.Add.caption:=searchrec.name;//加到listview下
end;
found:=findnext(searchrec);
end;
findclose(searchrec);
end;
node.expand(false); //双击时将展示下级节点
end;
程序很差劲,让大家见笑了
写的这么乱,不知大家看懂了没