Solved

Shfileoperation problem..

Posted on 2003-11-22
5
515 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month6 days, 3 hours left to enroll

626 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