Solved

CopyFile(blah blah blah)

Posted on 2001-06-06
4
431 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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