From 8e9852d03ef1247fd73c8a6d765d6459ee38b7bb Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 3 Nov 2015 13:10:08 +0100 Subject: auf Checkoptions umgestellt --- fernbedienung.lpr | 78 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/fernbedienung.lpr b/fernbedienung.lpr index e47e7b1..e7a2412 100644 --- a/fernbedienung.lpr +++ b/fernbedienung.lpr @@ -8,36 +8,48 @@ uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} - Classes, lesethreadunit + Classes, SysUtils, CustApp, lesethreadunit { you can add units after this }, - sysutils, lowlevelunit, irdecoderunit, gitupdateunit; + lowlevelunit, irdecoderunit, gitupdateunit; -var - irDecoder: tIRDecoder; - inputDatei: string; - cnt: longint; - watte,debug: boolean; +type + + { tFernbedienung } + + tFernbedienung = class(tCustomApplication) + protected + procedure doRun; override; + private + irDecoder: tIRDecoder; + inputDatei: string; + watte,debug: boolean; + public + constructor create(theOwner: TComponent); override; + end; + + { tFernbedienung } + +procedure tFernbedienung.doRun; +var + errorMsg: String; begin - inputDatei:=''; - watte:=false; - debug:=false; - for cnt:=1 to paramcount do begin - if paramstr(cnt)='-W' then begin - watte:=true; - continue; - end; - if paramstr(cnt)='-D' then begin - debug:=true; - continue; - end; - if inputDatei<>'' then - raise exception.create('Mehr als eine inputDatei angegeben!'); - inputDatei:=paramstr(cnt); + // quick check parameters + errorMsg:=checkOptions('WdI:','Watte debug Input:'); + + if (errorMsg='') and + not hasOption('I','Input') then + errorMsg:='Erwarte Input: ''-I $Input'''; + + if errorMsg<>'' then begin + showException(exception.create(errorMsg)); + terminate; + exit; end; - if inputDatei='' then - raise exception.create('Keine inputDatei angegeben!'); + inputDatei:=getOptionValue('I','Input'); + watte:=hasOption('W','Watte'); + debug:=hasOption('d','debug'); irDecoder:=tIRDecoder.create(inputDatei,extractfilepath(paramstr(0))+'befehle.konf',watte,debug); @@ -49,5 +61,23 @@ begin until false; irDecoder.free; + // stop program loop + Terminate; +end; + + +constructor tFernbedienung.create(theOwner: TComponent); +begin + inherited Create(TheOwner); + stopOnException:=True; +end; + +var + application: tFernbedienung; +begin + application:=tFernbedienung.Create(nil); + application.title:='Fernbedienung'; + application.run; + application.free; end. -- cgit v1.2.3