unit TryForm;
interface
uses
SysUtils, Windows, Messages, Classes,
Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
BtnWrong: TButton;
BtnTryFinally: TButton;
BtnTryTry: TButton;
procedure BtnWrongClick(Sender: TObject);
procedure BtnTryFinallyClick(Sender: TObject);
procedure BtnTryTryClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
procedure TForm1.BtnWrongClick(Sender: TObject);
var
I, J: Integer;
begin
Screen.Cursor := crHourglass;
J := 0;
for I := 1000 downto 0 do
J := J + J div I;
MessageDlg ('Total: ' + IntToStr (J),
mtInformation, [mbOK], 0);
Screen.Cursor := crDefault;
end;
procedure TForm1.BtnTryFinallyClick(Sender: TObject);
var
I, J: Integer;
begin
Screen.Cursor := crHourglass;
J := 0;
try
for I := 1000 downto 0 do
J := J + J div I;
MessageDlg ('Total: ' + IntToStr (J),
mtInformation, [mbOK], 0);
finally
Screen.Cursor := crDefault;
end;
end;
procedure TForm1.BtnTryTryClick(Sender: TObject);
var
I, J: Integer;
begin
Screen.Cursor := crHourglass;
J := 0;
try try
for I := 1000 downto 0 do
J := J + J div I;
MessageDlg ('Total: ' + IntToStr (J),
mtInformation, [mbOK], 0);
finally
Screen.Cursor := crDefault;
end;
except
on E: EDivByZero do
begin
raise Exception.Create ('Error in Algorithm');
end;
end;
end;
end.
|