?
Solved

Shfileoperation fails and replacing windows messages with custom one

Posted on 2003-12-03
6
Medium Priority
?
274 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
[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
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
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 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

Independent Software Vendors: 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 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