Re: Delphi CopyFile command


[ DelphiLand Discussion Forum ]

Posted by webmaster Guido on April 05, 19103 at 14:01:17:

In Reply to: CopyFile command posted by sam sgling07 on April 04, 19103 at 15:39:18:

: Someone please help me on this as well.
: I would like to copy a file from a directory to another directory. but when I specified the path using the COPYFILE(mPath+'xxx', mPath+'yyy',..), it gives me error - incompatible types: 'String' and 'PChar'. How to solve this problem? or is there any way or any command that I can use to copy the file.
: Thanks for helping me.
---------

COPYFILE expects parameters of the type PChar, not strings. So you have to convert the strings to PChar. Example:

var
  Source, Destination, mPath1, mPath2: string;
  ...
begin
  ...
  Source := mPath1 + 'xxx';
  Destination := mPath2 + 'yyy';
  CopyFile(PChar(Source),PChar(Destination),...);
  ...
end;

Related Articles and Replies:


[ DelphiLand Discussion Forum ]