Solved

SHFileOperation and Null terminated strings

Posted on 1998-02-18
8
305 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
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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