We help IT Professionals succeed at work.

Help with improving Procedures 2

Peter Kiers
Peter Kiers asked
on
230 Views
Last Modified: 2012-05-05
Dear Experts,

I know I have asked this before to improve a Procedure.
Could someone look at this procedure, and improve it.

procedure Tscreenf.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if IsModified then
  begin
    case MessageDlg('Do you want to save the current file?', mtConfirmation,
      [mbYes, mbNo, mbCancel], 0) of
      mrYes:
        begin
          Save1Click(Sender);
          SaveRecentFileList;
          Disconnect;
        end;
      mrNo:
        begin
          SaveRecentFileList;
          Disconnect;
        end;
      mrCancel: ;
    end;
  end
  else
    if socOpen then
    begin
      SaveRecentFileList;
      Disconnect;
    end else
    begin
      SaveRecentFileList;
    end;
end;

Greetings,

Peter Kiers
Comment
Watch Question

Mike LittlewoodEngineer

Commented:
Just a slight restructuring

procedure Tscreenf.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
   mr: TModalResult;
begin
  if IsModified then
  begin
    mr := MessageDlg('Do you want to save the current file?', mtConfirmation,
            [mbYes, mbNo, mbCancel], 0);

    case mr of
      mrYes,
      mrNo:
        begin
          if mr = mrYes then
            Save1Click(Sender);

          SaveRecentFileList;
          Disconnect;
        end;
      mrCancel: ;
    end;
  end
  else
  begin
    SaveRecentFileList;

    if socOpen then
      Disconnect;
  end;
end;
Engineer
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Peter KiersOperator

Author

Commented:
Thanks Mike.

Grz.

Peter Kiers
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.