Solved

Shfileoperation problem..

Posted on 2003-11-22
5
511 Views
Last Modified: 2010-04-05
Hi, i have a code below but the problem with this code is that when there is no diskette in drive it will display a message stating that there is no diskette retry and cancell, even if you press cancell it will still display the message in the last part 'File(s) were all copied.. Remove diskette now.. when pressing the cancel in the error message of windows.. all i want is to let windows handle all the error message.. can you please help me..


  f.wnd := handle;
       f.wfunc := FO_COPY;
       f.PFROM := pchar(src);
       f.PTO := pchar(dst);
       f.hNameMappings := nil;
       f.fflags :=  FOF_MULTIDESTFILES OR FOF_NOCONFIRMMKDIR OR FOF_ALLOWUNDO OR FOF_FILESONLY  OR
                    FOF_NOCONFIRMATION;

       result := ShFileOperation(F);

       if result <> 0 then
       begin
         if f.fAnyOperationsAborted = TRUE then
            MessageDlg('Copying of file(s) was cancelled...',mtWarning,
            [mbOk], 0)
         else
            MessageDlg('Copy Failed...', mtError,
           [mbOk], 0)
      end
      else
      begin
          if f.fAnyOperationsAborted = TRUE then
             MessageDlg('Copying of file(s) was cancelled...',mtWarning,
             [mbOk], 0)
          else
            MessageDlg('File(s) were all copied.. Remove diskette now..', mtInformation,
            [mbOk], 0)
      end;
0
Comment
Question by:therooster
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
Peter_ earned 250 total points
ID: 9805573
I use this code below to check if diskdrive, cd-drive and such have media before trying to access. SetErrorMode makes sure no dialogs are shown if test fails.

//---------------------------------------------------------------------------------

function DriveReady(Drive: string): Boolean;
var
  ErrorMode: word;
  DriveLetter: Char;
begin
 if (Length(Drive)=3) then
 begin
  //- Make sure the drive is ready -
  ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
  try
    { drive 1 = a, 2 = b, 3 = c, etc. }
    DriveLetter := Copy(Drive,1,1)[1];
    if DiskSize(Ord(DriveLetter) - $40) = -1 then
     Result := False
    else
     Result := True;
  finally
    { restore old error mode }
    SetErrorMode(ErrorMode);
  end;
 end
 else
  Result := True;
end;
0
 

Author Comment

by:therooster
ID: 9855412
Ic, but the problem is that when it encounters an error just like diskette is full or the copying of file was aborted choosing cancel will give the function lasterror = 0 meaning no error occur how can we trap tht error?
0
 
LVL 3

Expert Comment

by:Peter_
ID: 9866156
About "disc is full", I would suggest checking for available discspace before starting the operation. If the file is larger, then prompt user the operation was aborted and don't copy.

Have a look at this sample:

http://delphi.about.com/library/weekly/aa070699.htm
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

832 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