Solved

Shfileoperation problem..

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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