LICENSE
The contents of the Extended Document Object Model files are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this files except in compliance with the License. You may obtain a copy of the License at "http://www.mozilla.org/MPL/"
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.
The Original Code is "MiscUtils.pas".
The Initial Developer of the Original Code is Dieter Köhler (Heidelberg, Germany, "http://www.philo.de/"). Portions created by the Initial Developer are Copyright (C) 1999-2003 Dieter Köhler. All Rights Reserved.
Alternatively, the contents of this files may be used under the terms of the GNU General Public License Version 2 or later (the "GPL"), in which case the provisions of the GPL are applicable instead of those above. If you wish to allow use of your version of this files only under the terms of the GPL, and not to allow others to use your version of this files under the terms of the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the MPL or the GPL.
2004
The Miscellaneous Utilities Library contains auxiliary classes and functions which do not fit into one of the other units of the Open XML Utilities Package.
The latest version of this software is available at <http://www.philo.de/xml/>.
The Miscellaneous Utilities Library does not contain any components to be registered. So using it from inside your own projects is very simple: Add "MiscUtils" to the uses clause of your unit and make sure that the path to the location of the LangUtils.pas file is included in Delphi's list of library paths. To include it go to the Library section of Delphi's Environment Options dialog (see the menu item: "Tools/Environment Options ...").
TUtilsNoRefCount = class(TObject, IUnknown)
TUtilsNoRefCount is a non-reference-counted implementation of IUnknown.
Perhaps the biggest design flaw in Delphi is the way it implements interfaces, and in particular the TInterfacedObject class. At first glance, Delphi interfaces seem to be a good idea, since they brings automated garbage collection for objects to Delphi, promissing to redeem us from worries about memory leaks. However, the matter is now worse than before. The TInterfacedObject class created the potential for an even more difficult to detect kind of memory leaks. If the last interface variable pointing to a TInterfacedObject instance goes out of scope, the instance is freed, no matter whether an object variable to the instance still exists. Source code cannot be checked for such harmful object variables at compile time. Instead, such an automatically freed object remains unnoticed until the application later, perhaps in a completely different part of the source code, tries to access it. Only debugging threads can be as unpleasant as tracing the causes for the resulting access violation.
In other words: Using interfaces in combination with the TInterfacedObject class is not consistent with clean software design.
TUtilsNoRefCount avoids Delphi's automated garbage collection for interfaces by implementing the IUnknown interface follows:
function TUtilsNoRefCount._AddRef: Integer; begin Result := -1 end; function TUtilsNoRefCount._Release: Integer; begin Result := -1 end; function TUtilsNoRefCount.QueryInterface(const IID: TGUID; out Obj): HResult; begin if GetInterface(IID, Obj) then Result := 0 else Result := E_NoInterface; end;
TVersionDetail = ( vdAll, vdVersion, vdMajorVersion, vdMinorVersion, vdRelease, vdBuild );
TVersionDetail defines constants which denote parts of a version information structure.
function GetFileVersionStr(const FileName: string; const VersionDetail: TVersionDetail = vdAll): string;
GetFileVersionStr returns a string containing the version information or a part of it, as specified by the VersionDetail parameter, of the file indicated by the Filename parameter. If the file contains no associated version information, the GetFileVersionStr frunction returns an empty string.