Solved

SHFileOperation and Null terminated strings

Posted on 1998-02-18
8
325 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
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 2

Expert Comment

by:Waldek
ID: 1359561
Create string pFrom like filename1+#0+filename2+#0+...+#0#0
0
 

Author Comment

by:rmbec
ID: 1359562
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
ID: 1359563
pFrom must be a string I mean
0
Industry Leaders: 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!

 
LVL 5

Accepted Solution

by:
ronit051397 earned 70 total points
ID: 1359564
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
 
LVL 5

Expert Comment

by:ronit051397
ID: 1359565
The last line should be SHFileOperation(lpFile);
0
 

Author Comment

by:rmbec
ID: 1359566
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
ID: 1359567
pFrom must be a string
0
 

Author Comment

by:rmbec
ID: 1359568
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

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month5 days, 19 hours left to enroll

627 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