Solved

Shfileoperation fails and replacing windows messages with custom one

Posted on 2003-12-03
6
266 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 92
Working with hours 3 74
How to debug For loops? 3 63
how to update exe applicatio from internet ? 6 95
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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