Solved

Shfileoperation problem..

Posted on 2003-11-22
5
509 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now