Solved

SHFileOperation and Null terminated strings

Posted on 1998-02-18
8
288 Views
Last Modified: 2012-05-04
I am trying to use SHFileOperation to copy multiple files.  I am having difficulty constructing the pFrom string which requires the file names be seperated by a null character and if more than one file the whole string needs to be terminated with two null characters.  I originally did this program in Visual Basic 5 and it was real easy.  I need a stand-alone executable which is why I am learning Delphi.
0
Comment
Question by:rmbec
  • 3
  • 3
  • 2
8 Comments
 
LVL 2

Expert Comment

by:Waldek
Comment Utility
Create string pFrom like filename1+#0+filename2+#0+...+#0#0
0
 

Author Comment

by:rmbec
Comment Utility
That is what I tried first.
When I do that filename2 does not get appended.
Are pFrom, filename1, etc all type string?
0
 
LVL 2

Expert Comment

by:Waldek
Comment Utility
pFrom must be a string I mean
0
 
LVL 5

Accepted Solution

by:
ronit051397 earned 70 total points
Comment Utility
1. Place 2 TEdit's and a button in a form.
2. In Edit1 write the full path and file names of the file you want to copy, each is seperated by ';'.
3. In Edit2 write the destination Path/s, seperated by ';'.
4. Copy the code bellow and press the button.

uses ShellApi;

procedure TForm1.Button1Click(Sender: TObject);
var
  lpFile: TSHFileOpStruct;
  FFrom, FTo: string;
  pFrom, pTo: PChar;
  i: Integer;
begin
  with lpFile do
  begin
    Wnd:=Handle;
    wFunc := FO_COPY;
    FFrom := Edit1.Text + #0#0;
    for i := 1 to Length(FFrom) do if FFrom[i] = ';' then FFrom[i] := #0;
    pFrom := PChar(FFrom);
    FTo   := edit2.text + #0#0;
    for i := 1 to Length(FTo) do if FTo[i] = ';' then FTo[i] := #0;
    pTo   := PChar(FTo);
  end;
  SHFileOperation(lpFileOp);
end;

0
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.

 
LVL 5

Expert Comment

by:ronit051397
Comment Utility
The last line should be SHFileOperation(lpFile);
0
 

Author Comment

by:rmbec
Comment Utility
That won't work. As soon as I add the #0 to the null-terminated string it terminates the string.  The next strings do not get appended.  I've tried all sorts of ways to build this.  The closest I come is using an Character array but I need to dimension it after I calculate how many characters there are.
0
 
LVL 2

Expert Comment

by:Waldek
Comment Utility
pFrom must be a string
0
 

Author Comment

by:rmbec
Comment Utility
ronit;
My apologies, your method does work. I don;t know what I did earlier to cause it not to work.  I am not working with edit boxes, nor do I have control over file names so I can't use the ';' character since it is allowed in a file name.  I use a '?' instead. I certainly learned alot about how Delphi handles strings, arrays, pointers and memory blocks during my journey here.  Thanks for your help.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Filemaker 14 vs Delphi Embarcadero 7 159
Delphi XE7 Rest Client 2 172
Master Detail with TADODataset 4 96
Splash screen too shortlived 11 112
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

10 Experts available now in Live!

Get 1:1 Help Now