Solved

CopyFile(blah blah blah)

Posted on 2001-06-06
4
427 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
This ended up copying the file very quickly.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now