From f02bcc6ffe36d40904126093e72a046a7eb55635 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Mon, 7 Jun 2004 19:17:31 +0000 Subject: [PATCH] Added: VirtualTree utilities Added: Miscellaneous functions Fixed: minor comment adjustements --- X2UtApp.pas | 3 +- X2UtHandCursor.pas | 2 +- X2UtMisc.pas | 107 +++++++++++++++++++++++++++++++++++++++++ X2UtOS.pas | 6 +-- X2UtSingleInstance.pas | 63 +++++++++--------------- X2UtStrings.pas | 13 ++--- X2UtVirtualTree.pas | 63 ++++++++++++++++++++++++ 7 files changed, 202 insertions(+), 55 deletions(-) create mode 100644 X2UtMisc.pas create mode 100644 X2UtVirtualTree.pas diff --git a/X2UtApp.pas b/X2UtApp.pas index bb1cda9..ae4864b 100644 --- a/X2UtApp.pas +++ b/X2UtApp.pas @@ -8,7 +8,7 @@ :: :: Last changed: $Date$ :: Revision: $Rev$ - :: Author: $LastChangedBy$ + :: Author: $Author$ :$ :$ @@ -161,6 +161,7 @@ type property Version: TX2AppVersion read FVersion; end; + //:$ Returns a singleton App object function App(): TX2App; implementation diff --git a/X2UtHandCursor.pas b/X2UtHandCursor.pas index 7973254..0ef697a 100644 --- a/X2UtHandCursor.pas +++ b/X2UtHandCursor.pas @@ -10,7 +10,7 @@ :: :: Last changed: $Date$ :: Revision: $Rev$ - :: Author: $LastChangedBy$ + :: Author: $Author$ :$ :$ diff --git a/X2UtMisc.pas b/X2UtMisc.pas new file mode 100644 index 0000000..a1c1f98 --- /dev/null +++ b/X2UtMisc.pas @@ -0,0 +1,107 @@ +{ + :: X2UtMisc is a collection of functions not fitting into any of the other + :: categories. + :: + :: Subversion repository available at: + :: $URL$ + :: + :: Last changed: $Date$ + :: Revision: $Rev$ + :: Author: $Author$ + + :$ + :$ + :$ X2Utils is released under the zlib/libpng OSI-approved license. + :$ For more information: http://www.opensource.org/ + :$ /n/n + :$ /n/n + :$ Copyright (c) 2003 X2Software + :$ /n/n + :$ This software is provided 'as-is', without any express or implied warranty. + :$ In no event will the authors be held liable for any damages arising from + :$ the use of this software. + :$ /n/n + :$ Permission is granted to anyone to use this software for any purpose, + :$ including commercial applications, and to alter it and redistribute it + :$ freely, subject to the following restrictions: + :$ /n/n + :$ 1. The origin of this software must not be misrepresented; you must not + :$ claim that you wrote the original software. If you use this software in a + :$ product, an acknowledgment in the product documentation would be + :$ appreciated but is not required. + :$ /n/n + :$ 2. Altered source versions must be plainly marked as such, and must not be + :$ misrepresented as being the original software. + :$ /n/n + :$ 3. This notice may not be removed or altered from any source distribution. +} +unit X2UtMisc; + +interface + //:$ Returns IfTrue or IfFalse depending on the Value + function iif(const AValue: Boolean; const AIfTrue, AIfFalse: Integer): Integer; overload; + + //:$ Returns IfTrue or IfFalse depending on the Value + function iif(const AValue: Boolean; const AIfTrue, AIfFalse: String): String; overload; + + //:$ Compares two integers + //:: Returns 0 if the values are equal, 1 if Value1 is greater than Value2 and + //:: -1 when Value1 is less than Value2. + function CompareInt(const AValue1, AValue2: Integer): Integer; overload; + + //:$ Compares two integers + //:: Returns 0 if the values are equal, 1 if Value1 is greater than Value2 and + //:: -1 when Value1 is less than Value2. + function CompareInt(const AValue1, AValue2: Cardinal): Integer; overload; + + //:$ Compares two integers + //:: Returns 0 if the values are equal, 1 if Value1 is greater than Value2 and + //:: -1 when Value1 is less than Value2. + function CompareInt(const AValue1, AValue2: Int64): Integer; overload; + +implementation + +function iif(const AValue: Boolean; const AIfTrue, AIfFalse: Integer): Integer; +begin + if AValue then + Result := AIfTrue + else + Result := AIfFalse; +end; + +function iif(const AValue: Boolean; const AIfTrue, AIfFalse: String): String; +begin + if AValue then + Result := AIfTrue + else + Result := AIfFalse; +end; + +function CompareInt(const AValue1, AValue2: Integer): Integer; +begin + Result := 0; + if AValue1 > AValue2 then + Result := 1 + else if AValue1 < AValue2 then + Result := -1; +end; + +function CompareInt(const AValue1, AValue2: Cardinal): Integer; +begin + Result := 0; + if AValue1 > AValue2 then + Result := 1 + else if AValue1 < AValue2 then + Result := -1; +end; + +function CompareInt(const AValue1, AValue2: Int64): Integer; +begin + Result := 0; + if AValue1 > AValue2 then + Result := 1 + else if AValue1 < AValue2 then + Result := -1; +end; + +end. diff --git a/X2UtOS.pas b/X2UtOS.pas index 8370f6c..271730d 100644 --- a/X2UtOS.pas +++ b/X2UtOS.pas @@ -8,7 +8,7 @@ :: :: Last changed: $Date$ :: Revision: $Rev$ - :: Author: $LastChangedBy$ + :: Author: $Author$ :$ :$ @@ -43,9 +43,7 @@ uses Windows; type - { - :$ Enumerates the recognized Operating System versions - } + //:$ Enumeration of the recognized Operating System versions TX2OSVersion =(osUnknown, osWin95, osWin98, osWinME, osWinNT3, osWinNT4, osWin2K, osWinXP, osWin2003); diff --git a/X2UtSingleInstance.pas b/X2UtSingleInstance.pas index 38da6c1..ea2a577 100644 --- a/X2UtSingleInstance.pas +++ b/X2UtSingleInstance.pas @@ -7,7 +7,7 @@ :: :: Last changed: $Date$ :: Revision: $Rev$ - :: Author: $LastChangedBy$ + :: Author: $Author$ :$ :$ @@ -53,64 +53,45 @@ type procedure OnInstance(const ACmdLine: String); end; - { - :$ Checks for a previous instance of the application - - :: Returns False if a previous instance was found, True if this is the - :: first registered instance. ApplicationID must be unique to prevent - :: application conflicts, usage of a generated GUID is recommended. - - :! Set ANotify to False if you're using SingleInstance in a console - :! application without a message loop. - } + //:$ Checks for a previous instance of the application + //:: Returns False if a previous instance was found, True if this is the + //:: first registered instance. ApplicationID must be unique to prevent + //:: application conflicts, usage of a generated GUID is recommended. + //:! Set ANotify to False if you're using SingleInstance in a console + //:! application without a message loop. function SingleInstance(const AApplicationID: String; const ANotify: Boolean = True): Boolean; - { - :$ Registers the instance for notifications - - :: If an application wants to be notified of new instances it must - :: implement the IX2InstanceNotifier and register the interface using - :: this function. - } + //:$ Registers the instance for notifications + //:: If an application wants to be notified of new instances it must + //:: implement the IX2InstanceNotifier and register the interface using + //:: this function. procedure RegisterInstance(const ANotifier: IX2InstanceNotifier); - { - :$ Unregisters a previously registered instance - } + //:$ Unregisters a previously registered instance procedure UnregisterInstance(const ANotifier: IX2InstanceNotifier); - { - :$ Works like System.ParamCount, but uses the specified string instead - :$ of the actual command line - } + //:$ Works like System.ParamCount, but uses the specified string instead + //:$ of the actual command line function ParamCountEx(const ACmdLine: String): Integer; - { - :$ Works like System.ParamStr, but uses the specified string instead - :$ of the actual command line - } + //:$ Works like System.ParamStr, but uses the specified string instead + //:$ of the actual command line function ParamStrEx(const ACmdLine: String; AIndex: Integer): String; - { - :$ Works like SysUtils.FindCmdLineSwitch, but uses the specified string - :$ instead of the actual command line - } + //:$ Works like SysUtils.FindCmdLineSwitch, but uses the specified string + //:$ instead of the actual command line function FindCmdLineSwitchEx(const ACmdLine, ASwitch: String; const AChars: TSysCharSet; const AIgnoreCase: Boolean): Boolean; overload; - { - :$ Works like SysUtils.FindCmdLineSwitch, but uses the specified string - :$ instead of the actual command line - } + //:$ Works like SysUtils.FindCmdLineSwitch, but uses the specified string + //:$ instead of the actual command line function FindCmdLineSwitchEx(const ACmdLine, ASwitch: String): Boolean; overload; - { - :$ Works like SysUtils.FindCmdLineSwitch, but uses the specified string - :$ instead of the actual command line - } + //:$ Works like SysUtils.FindCmdLineSwitch, but uses the specified string + //:$ instead of the actual command line function FindCmdLineSwitchEx(const ACmdLine, ASwitch: String; const AIgnoreCase: Boolean): Boolean; overload; diff --git a/X2UtStrings.pas b/X2UtStrings.pas index edd6cf4..a7e963e 100644 --- a/X2UtStrings.pas +++ b/X2UtStrings.pas @@ -6,7 +6,7 @@ :: :: Last changed: $Date$ :: Revision: $Rev$ - :: Author: $LastChangedBy$ + :: Author: $Author$ :$ :$ @@ -37,13 +37,10 @@ unit X2UtStrings; interface - { - :$ Formats the specified size - - :: If KeepBytes is true, the size will be formatted for decimal separators - :: and 'bytes' will be appended. If KeepBytes is false the best suitable - :: unit will be chosen (KB, MB, GB). - } + //:$ Formats the specified size + //:: If KeepBytes is true, the size will be formatted for decimal separators + //:: and 'bytes' will be appended. If KeepBytes is false the best suitable + //:: unit will be chosen (KB, MB, GB). function FormatSize(const Bytes: Int64; KeepBytes: Boolean = False): String; implementation diff --git a/X2UtVirtualTree.pas b/X2UtVirtualTree.pas new file mode 100644 index 0000000..7b9ce88 --- /dev/null +++ b/X2UtVirtualTree.pas @@ -0,0 +1,63 @@ +{ + :: X2UtVirtualTree provides a set of functions commonly used with + :: TVirtualTree (http://www.delphi-gems.com/). + :: + :: Subversion repository available at: + :: $URL$ + :: + :: Last changed: $Date$ + :: Revision: $Rev$ + :: Author: $Author$ + + :$ + :$ + :$ X2Utils is released under the zlib/libpng OSI-approved license. + :$ For more information: http://www.opensource.org/ + :$ /n/n + :$ /n/n + :$ Copyright (c) 2003 X2Software + :$ /n/n + :$ This software is provided 'as-is', without any express or implied warranty. + :$ In no event will the authors be held liable for any damages arising from + :$ the use of this software. + :$ /n/n + :$ Permission is granted to anyone to use this software for any purpose, + :$ including commercial applications, and to alter it and redistribute it + :$ freely, subject to the following restrictions: + :$ /n/n + :$ 1. The origin of this software must not be misrepresented; you must not + :$ claim that you wrote the original software. If you use this software in a + :$ product, an acknowledgment in the product documentation would be + :$ appreciated but is not required. + :$ /n/n + :$ 2. Altered source versions must be plainly marked as such, and must not be + :$ misrepresented as being the original software. + :$ /n/n + :$ 3. This notice may not be removed or altered from any source distribution. +} +unit X2UtVirtualTree; + +interface +uses + VirtualTrees; + + //:$ Applies the sort order on the specified column + //:: When a column is already sorted, the sort order is reversed. + procedure SortColumn(const AHeader: TVTHeader; + const AColumn: TColumnIndex); + +implementation + +procedure SortColumn; +begin + with AHeader do + if SortColumn = AColumn then + SortDirection := TSortDirection(1 - Integer(SortDirection)) + else begin + SortColumn := AColumn; + SortDirection := sdAscending; + end; +end; + +end. + \ No newline at end of file