unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure makeError(p: byte);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled :=
not Timer1.Enabled;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
makeError(3);
end;
//p := Wahrscheinlichkeit eines Fehlers
procedure TForm1.makeError(p: byte);
var
i: byte;
typ: TMsgDlgType;
knoeppe:
set of TMsgDlgBtn;
const
typen:
array[0..4]
of TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);
knoeppes:
array[0..10]
of TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp);
begin
//denk an das Randomize
if random(100) < p
then
begin
typ := typen[random(5)];
knoeppe := [];
for i := 0
to random(6)
do //mit der 6 mal ein wenig rumprobieren
knoeppe := knoeppe + [knoeppes[i]];
MessageDlg('
Dies ist ein Fehler!', typ, knoeppe, 0);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
makeError(100);
end;
end.