Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Shfileoperation problem..

Posted on 2003-11-22
5
Medium Priority
?
518 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

926 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