Solved

CopyFile(blah blah blah)

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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