Solved

Shfileoperation fails and replacing windows messages with custom one

Posted on 2003-12-03
6
258 Views
Last Modified: 2010-04-05
 Hi, can we display my own message when the shfileoperation function fails?
 such as diskette is full or cannot read from a specified device..  because i try using the try..except still it does not work. can you help me please?
0
Comment
Question by:vbeginner
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
shfileoperation is a function,
which returns a value <> 0,
if the operation fails

which number which failure represents i do not know,
maybe it is needed to use the GetLastError-api

a sceleton could shown like

var
  op_result : Integer;
begin
  op_result := shfileoperation(....);
  if op_result <> 0 then
  begin
     //yourmessage here
     //or
     case op_result of
       .....
     end;
  end;

meikl ;-)
0
 

Author Comment

by:vbeginner
Comment Utility
meikl, a problem with shfileoperation is that when it displays a message box and the user is prompted to select retry or quit and it selects quit it returns zero..
0
 
LVL 33

Expert Comment

by:Slick812
Comment Utility
hello vbeginner, not to sure about what to do here for your request, The SHFileOperation will show the error messages for disk full and others. . . here is some code for a SHFileOperation, I get the Result of thethis function in Res1, as you know if Res1 is Zero then operation was sucessful (at least to the OS, which may NOT be the same opinion for you, since it may not have done anything).  This Res1 will be a certain value for certain failures. .  I did not find any documentation about these result values, but the two values I used in one of my app were
117
and
1026

there may or may not be other values, and this value may or may not be consistant between different windows versions. . . I do not have time now to research this. . .
If the user aborts, (presses the Cancel button, instead of the Retry button), I am not sure that there is a way to any info about what the "Problem" may have been for the Error message. . .

procedure TForm1.sbut_ShellOpClick(Sender: TObject);
var
shFileOpRec : TSHFileOpStruct;
Res1: Integer;
ErrorStr: String;
begin
with shFileOpRec do
  begin
  Wnd    := Handle ;
  wFunc  := FO_COPY;  // what kind of operation
  pFrom  := 'E:\Bmp1.bmp' ;     // from
  pTo    := 'A:\' ;       // to

  fFlags :=  FOF_FILESONLY or FOF_ALLOWUNDO or FOF_SIMPLEPROGRESS {or FOF_NOCONFIRMATION} or FOF_NOERRORUI;
{the  FOF_NOERRORUI will supress all of the error messages and User Choose (Retry, Cancel)}
  // FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;

  hNameMappings         := nil; //  Pointer;
  lpszProgressTitle     := 'Progress Title';
  end;
Res1 := SHFileOperation(shFileOpRec);
if Res1 <> 0 then
  begin
  if Res1 = 117 then
  ErrorStr := 'ERROR - Not Enough Disk Space on Drive to Copy file'
  else
  if Res1 = 1026 then
  ErrorStr := 'ERROR - From File Does NOT exist, Copy Failed'
  else
  ErrorStr := 'Unknown ERROR';
  if GetLastError <> 0 then
  ErrorStr := ErrorStr + #10 + SysErrorMessage(GetLastError);
  ShowMessage(ErrorStr);
  end else
if shFileOpRec.fAnyOperationsAborted = true then
  begin
  ShowMessage('Operation was Aborted');
  end;

end;
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 33

Expert Comment

by:Slick812
Comment Utility
If you want more control, you might consider using another method than SHFileOperation, you could even check for the free Disk space BEFORE you call the SHFileOperation
0
 
LVL 2

Expert Comment

by:-Karamja-
Comment Utility
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
PAQ - No Refund

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Karamja (Alan)
EE Cleanup Volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
Comment Utility
PAQed - no points refunded (of 250)

Computer101
E-E Admin
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

743 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

7 Experts available now in Live!

Get 1:1 Help Now