procedure TForm1.Button2Click(Sender: TObject);
var
dir,dir2:string;
begin
dir:='d:'+'\'+Pchar(label1.Caption);
if not directoryexists(dir) then
if not createdir(dir) then
begin
showmessage('无法创建');
end;
dir2:=dir+'\'+ExtractFileName(openDialog1.FileName);
CopyFile(Pchar(edit1.text),Pchar(dir2),true);
end;譬如label1.caption为test,我这样写的话,只是在d盘下创建了test文件夹,但文件并未复制到文件夹中。如果我直接写dir:='d:'+'\'+'test'的话,就创建test文件夹并且把文件复制到test文件夹中。请问如果我非要用label1.caption的话,要怎样写呢?
var
dir,dir2:string;
begin
dir:='d:'+'\'+Pchar(label1.Caption);
if not directoryexists(dir) then
if not createdir(dir) then
begin
showmessage('无法创建');
end;
dir2:=dir+'\'+ExtractFileName(openDialog1.FileName);
CopyFile(Pchar(edit1.text),Pchar(dir2),true);
end;譬如label1.caption为test,我这样写的话,只是在d盘下创建了test文件夹,但文件并未复制到文件夹中。如果我直接写dir:='d:'+'\'+'test'的话,就创建test文件夹并且把文件复制到test文件夹中。请问如果我非要用label1.caption的话,要怎样写呢?
dir:='d:'+'\'+Pchar(label1.Caption)是一个以#0结尾的串,差别就在这个#0
非要用label1.caption的话就不要PChar,dir:='d:'+'\'+label1.Caption;
调用api函数 phar一下.
现在我改成了
dir:='d:\shuju\'+edit4.text+'\硕士论文';
或者dir:=pchar('d:\shuju\'+edit4.text+'\硕士论文')
仍然显示无法创建,为什么呢?
难道是.caption和.text有区别吗?