home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / STRRES / MAIN.PAS < prev    next >
Pascal/Delphi Source File  |  1998-04-13  |  1KB  |  64 lines

  1. {
  2.   Compile resource file from DOS before running this program:
  3.     brc32 -r errmsg.rc
  4. }
  5.  
  6. unit Main;
  7.  
  8. interface
  9.  
  10. uses
  11.   SysUtils, Windows, Messages, Classes, Graphics, Controls,
  12.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls;
  13.  
  14. type
  15.   TMainForm = class(TForm)
  16.     BitBtn1: TBitBtn;
  17.     BitBtn2: TBitBtn;
  18.     Bevel1: TBevel;
  19.     procedure BitBtn1Click(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.     function ErrorCancel(ErrNum: Word): Boolean;
  23.   public
  24.     { Public declarations }
  25.   end;
  26.  
  27. var
  28.   MainForm: TMainForm;
  29.  
  30. implementation
  31.  
  32. {$R *.DFM}
  33. {$R Errmsg.Res}    { Load string table resource }
  34.  
  35. const
  36.   maxErrorNumber = 6;
  37.  
  38. function TMainForm.ErrorCancel(ErrNum: Word): Boolean;
  39. var
  40.   ErrMsg: String;
  41.   ErrStr: array[0 .. 63] of Char;
  42. begin
  43.   if LoadString(HInstance, ErrNum, ErrStr, 63) <= 0 then
  44.     StrPCopy(ErrStr, 'Unknown problem');  { ErrStr := '...'; }
  45.   ErrMsg := 'Error #:' + IntToStr(ErrNum) + ' ' + StrPas(ErrStr);
  46.   ErrorCancel :=
  47.     MessageDlg(ErrMsg, mtError, [mbRetry, mbCancel], 0) = mrCancel
  48. end;
  49.  
  50. procedure TMainForm.BitBtn1Click(Sender: TObject);
  51. var
  52.   ErrNum: Integer;
  53.   Canceled: Boolean;
  54. begin
  55.   Canceled := False;
  56.   repeat
  57.     ErrNum := 1 + Random(maxErrorNumber);  { Simulate error }
  58.     if ErrNum <> 0 then
  59.       Canceled := ErrorCancel(ErrNum);
  60.   until Canceled;
  61. end;
  62.  
  63. end.
  64.