Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SHFileOperation and Null terminated strings

Posted on 1998-02-18
8
Medium Priority
?
333 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Accepted Solution

by:
ronit051397 earned 210 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

721 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