Solved

CopyFile(blah blah blah)

Posted on 2001-06-06
4
432 Views
Last Modified: 2010-04-06
Hello all,

Here is what I'm trying to do...

Dir := Ini.ReadString('Directory', 'CurDir', 'c:\');

CopyFile(Dir + '\myfile', '.\backup\myfile);

I'm getting an error because string and pchar are different types.

I need to know the proper way to do this.
0
Comment
Question by:fibdev
  • 2
4 Comments
 
LVL 3

Expert Comment

by:nnbbb09
ID: 6161212
you should just be able to typecast the string to a pchar.

eg : PChar(Dir+'\myfile')
0
 

Accepted Solution

by:
asburgoyne earned 50 total points
ID: 6161471
Just define a PChar variable and do as follows:-

MyPChar := StrAlloc(256);
StrPCopy(MyPChar, Dir + '\myfile');
CopyFile(MyPChar, '.\backup\myfile);
StrDispose(MyPChar);
0
 
LVL 3

Author Comment

by:fibdev
ID: 6162537
What I ended up doing is just using a procedure to handle the file operation.

Thanks anyway.

procedure TForm1.DoCopy(Source, Dest: string);
var
  SrcFile : Integer;
  DestFile : Integer;
  S : string;
  RetCode : Longint;
  OpenFileBuf   : TOFStruct;
  FName : array[ 0..255 ] of Char;
begin
  StrPCopy( FName, Source );
  SrcFile := LZOpenFile( FName, OpenFileBuf, of_Read );
  StrPCopy( FName, Dest );
  DestFile := LZOpenFile( FName, OpenFileBuf, of_Create );

  RetCode := LZCopy( SrcFile, DestFile );
  if RetCode >= 0 then
  begin
    LZClose( SrcFile );
    LZClose( DestFile );
  end
  else
  begin
    Str( RetCode, S );
    MessageDlg( 'Could not copy ' + Source + ' to ' +
                Dest + #13 + 'Error Code = ' + S, mtError, [mbOk], 0 );
  end;
end;
0
 
LVL 3

Author Comment

by:fibdev
ID: 6162538
This ended up copying the file very quickly.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question