鄙人在用COPY的时候总是想着Delphi中的源码的注释,下面是它的注释
{ limit index to satisfy 1 <= index <= Length(src) }
但是呢我们在用的时候index可以为0,也可以为1,一般情况下我们都是用1的,呵呵,
纳闷呀这两个参数传进去得到的值是一样的
...全文
45732打赏收藏
讨论一下Copy函数的问题,顺便放分
鄙人在用COPY的时候总是想着Delphi中的源码的注释,下面是它的注释 { limit index to satisfy 1 <= index <= Length(src) } 但是呢我们在用的时候index可以为0,也可以为1,一般情况下我们都是用1的,呵呵, 纳闷呀这两个参数传进去得到的值是一样的
uses shellapi;
var tmp:string; //全局变量
function WinCOPY(SourceFileName: String; TargetFileName: String): String;
var
OpStruc: TSHFileOpStruct;
FromBuf,ToBuf: Array[0..128] of Char;
opstr, Wnd:integer;
begin
FillChar(FromBuf,Sizeof(FromBuf),0);
FillChar(ToBuf,Sizeof(ToBuf),0);
//用0初始化FromBuf和ToBuf数组
StrPCopy(FromBuf,Pchar(SourceFileName));
StrPCopy(ToBuf,Pchar(TargetFileName));
//分别在 FromBuf和ToBuf数组中填入操作的源目录及目标目录
//开始填充OpStruc记录
with OpStruc do
begin
// Wnd:=Handle;
wFunc:=FO_COPY;
//复制操作
pFrom:=@FromBuf;
pTo:=@ToBuf;
fFlags:=FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted:=False;
hNameMappings:=nil;
lpszProgressTitle:=nil;
OpStR:= SHFileOperation(OpStruc);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
tmp:=OpenDialog1.FileName;
if SaveDialog1.Execute then
WinCOPY(tmp,(SaveDialog1.FileName+ExtractFileExt(OpenDialog1.FileName)));
showmessage('文件复制成功!');
end;