diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2009-10-14 14:56:18 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2009-10-14 14:56:18 +0200 |
commit | ab9e1dbe313d975c2c45caab0479982df33d893b (patch) | |
tree | 51c2641ae19d0bb1a22215b4bc4fe586e9cfdc6a /src | |
parent | f3711699e6dc6f80e9da39eed2acc3b08074367f (diff) | |
download | fpGUI-ab9e1dbe313d975c2c45caab0479982df33d893b.tar.xz |
A few new help functions and logevent() implemented.
Signed-off-by: Graeme Geldenhuys <graeme@mastermaths.co.za>
Diffstat (limited to 'src')
-rw-r--r-- | src/nvUtilities.pas | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/src/nvUtilities.pas b/src/nvUtilities.pas index 7b57cfa3..7b818649 100644 --- a/src/nvUtilities.pas +++ b/src/nvUtilities.pas @@ -17,6 +17,23 @@ const Quote = ''''; DoubleQuote = '"'; + // -- Logging -- +type + LogAspect = ( LogStartup, + LogShutdown, + LogSettings, + LogI18n, + LogParse, + LogDisplay, + LogSearch, + LogNHM, + LogViewStub, + LogObjConstDest, + LogDebug + ); + LogAspects = SET OF LogAspect; + +procedure LogEvent(const aLogAspect: LogAspect; const anEventDescription: String); // Removes and returns the first value in a separated // value list (removes quotes if found) @@ -42,15 +59,93 @@ function Between( const Value: longint; const Limit1: longint; const Limit2: lon Operator = (ARect: TRect; BRect: TRect): boolean; +// Destroy the objects stored in List and clear the list. +Procedure ClearListAndObjects( List: TList ); +// Destroy the objects stored in the list and then destroy the list itself +// And set the reference to nil +Procedure DestroyListAndObjects( Var List: TList ); +// Destroy the objects stored in the list. +// You probably want to use one of the two functions above. +Procedure DestroyListObjects( List: TList ); + +Procedure AddList( Source, Dest: TList ); +Procedure AssignList( Source, Dest: TList ); + + + +var + startTime : Cardinal; + lastTime : Cardinal; + activeLogAspects : LogAspects; + infoMessage1 : String; + infoMessage2 : String; + implementation uses fpg_utils + ,fpg_main + ,ACLStringUtility ; // character // from utf8tools package (pulls in LCL requirement which we MUST change) // ; + Function GetAspectPrefix(const aLogAspect: LogAspect): String; + Begin + Case aLogAspect of + LogStartup : result := 'Startup'; + LogShutdown : result := 'Start'; + LogSettings : result := 'Settings'; + LogI18n : result := 'I18n'; + LogParse : result := 'Parse'; + LogDisplay : result := 'Display'; + LogSearch : result := 'Search'; + LogNHM : result := 'NewHelpManager'; + LogViewStub : result := 'ViewStub'; + LogObjConstDest : result := 'ObjConstDest'; + LogDebug : result := 'Debug'; + else result := 'Unknown'; + end; + End; + + + Procedure SetLogAspects(const aCommaSeparatedListOfAspectNames : String); + Var + tmpAspects : TStringList; + i : Integer; + Begin + tmpAspects := TStringList.Create; + StrExtractStrings(tmpAspects, aCommaSeparatedListOfAspectNames, [','], #0); + + for i:=0 to tmpAspects.count-1 do + begin + if tmpAspects[i] = 'LogStartup' then activeLogAspects := activeLogAspects + [ LogStartup ]; + if tmpAspects[i] = 'LogShutdown' then activeLogAspects := activeLogAspects + [ LogShutdown ]; + if tmpAspects[i] = 'LogSettings' then activeLogAspects := activeLogAspects + [ LogSettings ]; + if tmpAspects[i] = 'LogI18n' then activeLogAspects := activeLogAspects + [ LogI18n ]; + if tmpAspects[i] = 'LogParse' then activeLogAspects := activeLogAspects + [ LogParse ]; + if tmpAspects[i] = 'LogDisplay' then activeLogAspects := activeLogAspects + [ LogDisplay ]; + if tmpAspects[i] = 'LogSearch' then activeLogAspects := activeLogAspects + [ LogSearch ]; + if tmpAspects[i] = 'LogNHM' then activeLogAspects := activeLogAspects + [ LogNHM ]; + if tmpAspects[i] = 'LogViewStub' then activeLogAspects := activeLogAspects + [ LogViewStub ]; + if tmpAspects[i] = 'LogObjConstDest' then activeLogAspects := activeLogAspects + [ LogObjConstDest ]; + if tmpAspects[i] = 'LogDebug' then activeLogAspects := activeLogAspects + [ LogDebug ]; + end; + + tmpAspects.Destroy; + End; + +procedure LogEvent(const aLogAspect: LogAspect; const anEventDescription: String); +var + tmpMessage: String; +begin + if (aLogAspect IN activeLogAspects) then + begin + tmpMessage := 'Log[' + GetAspectPrefix(aLogAspect) + '] ' + anEventDescription; + debugln(tmpMessage); + end; +end; Function ExtractNextValue( var S: string; const Separator: string ): string; @@ -145,5 +240,57 @@ begin (ARect.Right = BRect.Right); end; +// Destroy the objects stored in List +// and clear the list. +Procedure ClearListAndObjects( List: TList ); +begin + DestroyListObjects( List ); + List.Clear; +end; + +// Destroy the objects stored in the list +// and then destroy the list itself. +Procedure DestroyListAndObjects( Var List: TList ); +begin + if not Assigned( List ) then + exit; + + DestroyListObjects( List ); + List.Free; + List := nil; +end; + +Procedure DestroyListObjects( List: TList ); +var + Index: longint; +begin + for Index := 0 to List.Count - 1 do + begin + if List[ Index ] <> nil then + begin + TObject( List[ Index ] ).Free; + List[ Index ] := nil; + end; + end; +end; + +Procedure AddList( Source, Dest: TList ); +var + i: longint; +begin + // expand the destination list to what's required + Dest.Capacity := Dest.Capacity + Source.Capacity; + for i:= 0 to Source.Count - 1 do + Dest.Add( Source[ i ] ); +end; + +Procedure AssignList( Source, Dest: TList ); +begin + Dest.Clear; + AddList( Source, Dest ); +end; + + + end. |