?
Solved

CopyFile(blah blah blah)

Posted on 2001-06-06
4
Medium Priority
?
440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Technology Partners: 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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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