unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Unit2, end_uses; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private TestProj: TTestProject; public { Public declarations } end; var Form1: TForm1; implementation uses ErrorListUnit; {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin TestProj := TTestProject.Create; end; procedure TForm1.FormDestroy(Sender: TObject); begin TestProj.Free; end; procedure StringAdd(var Base: String; const Delimiter, AddString: String); begin if Base <> '' then begin Base := Base + Delimiter + AddString; end else begin Base := AddString; end; end; procedure TForm1.Button1Click(Sender: TObject); var I: Integer; ErrorMsg: String; begin ErrorList.Clear; if TestProj.LoadFromFile then begin ShowMessage('TestProj.LoadFromFileは成功しました'); end else begin ShowMessage('TestProj.LoadFromFileは失敗しました'); Assert(ErrorList.Count <> 0); ErrorMsg := ''; for I := 0 to ErrorList.Count - 1 do begin StringAdd(ErrorMsg, #13#10, ErrorList[I].Message); end; ShowMessage(ErrorMsg); end; end; type E_MyException1 = class(Exception); E_MyException2 = class(Exception); procedure TForm1.Button2Click(Sender: TObject); var StrValue: String; IntValue: Integer; Result: Extended; ErrorIndex: Integer; begin// ErrorList.Clear; StrValue := Edit1.Text; if ErrorList.Count = 0 then if TryStrToInt(StrValue, IntValue) = False then ErrorList.Add(E_MyException1.Create('値が数値じゃない')); if ErrorList.Count = 0 then if IntValue = 0 then ErrorList.Add(E_MyException2.Create('値が0はよくない')); if ErrorList.Count = 0 then begin Result := IntValue / 10; ShowMessage( FloatToStr(Result) ); end else begin ErrorIndex := ErrorList.IndexOfClass(Exception, 0); begin while ErrorIndex <> -1 do begin ShowMessage(ErrorList.Items[ErrorIndex].Message); ErrorIndex := ErrorList.IndexOfClass(Exception, ErrorIndex + 1); end; end; end; end; end.