Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Shfileoperation fails and replacing windows messages with custom one

Posted on 2003-12-03
6
Medium Priority
?
278 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
ID: 9865665
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
ID: 9879184
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 34

Expert Comment

by:Slick812
ID: 9935018
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
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!

 
LVL 34

Expert Comment

by:Slick812
ID: 9935035
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-
ID: 12382355
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
ID: 12417734
PAQed - no points refunded (of 250)

Computer101
E-E Admin
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 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