📄 rm_stbase.pas
字号:
(* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file 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 TurboPower SysTools
*
* The Initial Developer of the Original Code is
* TurboPower Software
*
* Portions created by the Initial Developer are Copyright (C) 1996-2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** *)
{*********************************************************}
{* SysTools: StBase.pas 4.03 *}
{*********************************************************}
{* SysTools: Base unit for SysTools *}
{*********************************************************}
{$I RM_StDefine.inc}
unit RM_StBase;
interface
uses
Windows,
Classes, SysUtils, Messages, StdCtrls,
RM_StConst;
const
{.Z+}
StMaxBlockSize = MaxLongInt;
{.Z-}
type
{!!.01 - moved from StBase.pas }
TStLineTerminator = ( {possible line terminators...}
ltNone, {..no terminator, ie fixed length lines}
ltCR, {..carriage return (#13)}
ltLF, {..line feed (#10)}
ltCRLF, {..carriage return/line feed (#13/#10)}
ltOther); {..another character}
{!!.01 - end moved }
type
{$IFDEF CBuilder}
TStHwnd = Integer;
{$ELSE}
TStHwnd = HWND;
{$ENDIF}
{-SysTools exception class tree}
type
EStException = class(Exception) {ancestor to all SysTools exceptions}
protected {private}
FErrorCode : Longint;
public
constructor CreateResTP(Ident : LongInt; Dummy : Word);
constructor CreateResFmtTP(Ident : Longint; const Args : array of const;
Dummy : Word);
property ErrorCode : LongInt
read FErrorCode
write FErrorCode;
end;
EStExceptionClass = class of EStException;
EStContainerError = class(EStException); {container exceptions}
EStSortError = class(EStException); {sorting exceptions}
EStRegIniError = class(EStException); {registry/INI file exceptions}
EStBCDError = class(EStException); {Bcd exceptions}
EStStringError = class(EStException); {String class exceptions}
EStVersionInfoError = class(EStException); {Version info exception}
EStNetException = class(EStException); {Network exception}
EStBarCodeError = class(EStException); {BarCode exception}
EStPNBarCodeError = class(EStException); {PostNet BarCode exception}
EStStatError = class(EStException); {statistics exceptions}
EStFinError = class(EStException); {Financial exceptions}
EStMimeError = class(EStException); {Mime exceptions}
EStToHTMLError = class(EStException); {ToHTML exceptions}
EStSpawnError = class(EStException); {SpawnApplication errors}
EStMMFileError = class(EStException); {MemoryMappedFile errors}
EStBufStreamError =class(EStException); {Buffered stream errors}
EStRegExError = class(EStException); {RegEx errors}
EStDecMathError = class(EStException); {Decimal math errors}
EStPRNGError = class(EStException); {Random number errors}
EStExprError = class(EStException) {expression evaluator exceptions}
protected {private}
FErrorCol : Integer;
public
constructor CreateResTPCol(Ident : Longint; Column : Integer; Dummy : Integer);
property ErrorColumn : Integer
{-Returns the string position at the start of the token where
the error was detected}
read FErrorCol;
end;
const
{.Z+}
StMaxFileLen = 260;
StRLEMaxCount = 127; { Used by RLE }
StRLERunMode = $80; { Used by RLE }
{.Z-}
const
{.Z+}
{used by CompareLetterSets for estimating word similarity}
StLetterValues : array['A'..'Z'] of Byte = (
3 {A} , 6 {B} , 5 {C} , 4 {D} , 3 {E} , 5 {F} , 5 {G} , 4 {H} , 3 {I} ,
8 {J} , 7 {K} , 4 {L} , 5 {M} , 3 {N} , 3 {O} , 5 {P} , 7 {Q} , 4 {R} ,
3 {S} , 3 {T} , 4 {U} , 6 {V} , 5 {W} , 8 {X} , 8 {Y} , 9 {Z} );
StHexDigits : array[0..$F] of Char = '0123456789ABCDEF';
DosDelimSet : set of Char = ['\', ':', #0];
{$IFDEF VERSION4} { Delphi/Builder 3 doesn't like widestring typed constants }
StHexDigitsW : WideString = '0123456789ABCDEF';
DosDelimSetW : WideString = '\:';
{$ENDIF}
{.Z-}
type
{.Z+}
TSmallArray = array[0..StMaxFileLen-1] of Char;
BTable = array[0..255] of Byte; {Table used by Boyer-Moore search routines}
{.Z-}
type
{.Z+}
PDouble = ^Double;
TDoubleArray = array[0..(stMaxBlockSize div SizeOf(Double))-1] of Double;
PDoubleArray = ^TDoubleArray;
TIntArray = array[0..(StMaxBlockSize div SizeOf(Integer))-1] of Integer;
PIntArray = ^TIntArray;
{.Z-}
type
{the SysTools floating point type}
{$IFOPT N+}
TStFloat = Extended;
{$ELSE}
TStFloat = Real;
{$ENDIF}
const
WMCOPYID : DWORD = $AFAF;
type
TStNode = class(TPersistent)
{.Z+}
protected {private}
FData : Pointer;
{.Z-}
public
constructor Create(AData : Pointer);
virtual;
property Data : Pointer
read FData
write FData;
end;
{.Z+}
TStNodeClass = class of TStNode;
{.Z-}
TStContainer = class;
TCompareFunc =
function(Data1, Data2 : Pointer) : Integer;
TStCompareEvent =
procedure(Sender : TObject; Data1, Data2 : Pointer; var Compare : Integer)
of object;
TDisposeDataProc =
procedure(Data : Pointer);
TStDisposeDataEvent =
procedure(Sender : TObject; Data : Pointer)
of object;
TLoadDataFunc =
function(Reader : TReader) : Pointer;
TStLoadDataEvent =
procedure(Sender : TObject; Reader : TReader; var Data : Pointer)
of object;
TStoreDataProc =
procedure(Writer : TWriter; Data : Pointer);
TStStoreDataEvent =
procedure(Sender : TObject; Writer : TWriter; Data : Pointer)
of object;
TStringCompareFunc =
function(const String1, String2 : string) : Integer;
TStStringCompareEvent =
procedure(Sender : TObject; const String1, String2 : string; var Compare : Integer)
of object;
TUntypedCompareFunc =
function(const El1, El2) : Integer;
TStUntypedCompareEvent =
procedure(Sender : TObject; const El1, El2; var Compare : Integer)
of object;
TIterateFunc =
function(Container : TStContainer; Node : TStNode; OtherData : Pointer) : Boolean;
TIteratePointerFunc =
function(Container : TStContainer; Data, OtherData : Pointer) : Boolean;
TIterateUntypedFunc =
function(Container : TStContainer; var Data; OtherData : Pointer) : Boolean;
TStContainer = class(TPersistent)
{.Z+}
protected {private}
{property instance variables}
FCompare : TCompareFunc;
FDisposeData : TDisposeDataProc;
FLoadData : TLoadDataFunc;
FStoreData : TStoreDataProc;
{event variables}
FOnCompare : TStCompareEvent;
FOnDisposeData : TStDisposeDataEvent;
FOnLoadData : TStLoadDataEvent;
FOnStoreData : TStStoreDataEvent;
{private instance variables}
{$IFDEF ThreadSafe}
conThreadSafe : TRTLCriticalSection;
{$ENDIF}
procedure SetCompare(C : TCompareFunc);
procedure SetDisposeData(D : TDisposeDataProc);
procedure SetLoadData(L : TLoadDataFunc);
procedure SetStoreData(S : TStoreDataProc);
protected
conNodeClass : TStNodeClass;
conNodeProt : Integer;
FCount : Longint;
{protected undocumented methods}
function AssignPointers(Source : TPersistent; AssignData : TIteratePointerFunc) : boolean;
function AssignUntypedVars(Source : TPersistent; AssignData : TIterateUntypedFunc) : boolean;
procedure ForEachPointer(Action : TIteratePointerFunc; OtherData : Pointer);
virtual;
procedure ForEachUntypedVar(Action : TIterateUntypedFunc; OtherData : pointer);
virtual;
procedure GetArraySizes(var RowCount, ColCount, ElSize : Cardinal);
virtual;
procedure SetArraySizes(RowCount, ColCount, ElSize : Cardinal);
virtual;
function StoresPointers : boolean;
virtual;
function StoresUntypedVars : boolean;
virtual;
{protected documented}
procedure IncNodeProtection;
{-Prevent container Destroy from destroying its nodes}
procedure DecNodeProtection;
{-Allow container Destroy to destroy its nodes}
procedure EnterCS;
{-Enter critical section for this instance}
procedure LeaveCS;
{-Leave critical section for this instance}
{.Z-}
public
constructor CreateContainer(NodeClass : TStNodeClass; Dummy : Integer);
{-Create an abstract container (called by descendants)}
destructor Destroy;
override;
{-Destroy a collection, and perhaps its nodes}
procedure Clear;
virtual; abstract;
{-Remove all elements from collection}
procedure DisposeNodeData(P : TStNode);
{-Destroy the data associated with a node}
{wrapper methods for using events or proc/func pointers}
function DoCompare(Data1, Data2 : Pointer) : Integer;
virtual;
procedure DoDisposeData(Data : Pointer);
virtual;
function DoLoadData(Reader : TReader) : Pointer;
virtual;
procedure DoStoreData(Writer : TWriter; Data : Pointer);
virtual;
procedure LoadFromFile(const FileName : string);
dynamic;
{-Create a container and its data from a file}
procedure LoadFromStream(S : TStream);
dynamic; abstract;
{-Create a container and its data from a stream}
procedure StoreToFile(const FileName : string);
dynamic;
{-Create a container and its data from a file}
procedure StoreToStream(S : TStream);
dynamic; abstract;
{-Write a container and its data to a stream}
property Count : LongInt
{-Return the number of elements in the collection}
read FCount;
property Compare : TCompareFunc
{-Set or read the node comparison function}
read FCompare
write SetCompare;
property DisposeData : TDisposeDataProc
{-Set or read the node data dispose function}
read FDisposeData
write SetDisposeData;
property LoadData : TLoadDataFunc
{-Set or read the node data load function}
read FLoadData
write SetLoadData;
property StoreData : TStoreDataProc
{-Set or read the node data load function}
read FStoreData
write SetStoreData;
{events}
property OnCompare : TStCompareEvent
read FOnCompare
write FOnCompare;
property OnDisposeData : TStDisposeDataEvent
read FOnDisposeData
write FOnDisposeData;
property OnLoadData : TStLoadDataEvent
read FOnLoadData
write FOnLoadData;
property OnStoreData : TStStoreDataEvent
read FOnStoreData
write FOnStoreData;
end;
TAssignRowData = record
RowNum : Integer;
Data : array [0..0] of Byte;
end;
{.Z+}
{ base component for SysTools non-visual components}
TStComponent = class(TComponent)
protected {private}
function GetVersion : string;
procedure SetVersion(const Value : string);
published
property Version : string
read GetVersion
write SetVersion
stored False;
end;
{ base component for TStExpressionEdit component }
TStBaseEdit = class(TEdit)
protected {private}
function GetVersion : string;
procedure SetVersion(const Value : string);
published
property Version : string
read GetVersion
write SetVersion
stored False;
end;
{.Z-}
{---Generic node routines---}
function DestroyNode(Container : TStContainer; Node : TStNode;
OtherData : Pointer) : Boolean;
{-Generic function to pass to iterator to destroy a container node}
{---WIN32 short string routines---}
{$IFDEF WStrings}
function AnsiUpperCaseShort32(const S : string) : string;
{-Ansi uppercase for H- strings in WIN32}
function AnsiCompareTextShort32(const S1, S2: string): Integer;
{-Case-insensitive compare function for H- strings in WIN32}
function AnsiCompareStrShort32(const S1, S2: string): Integer;
{-Case-sensitive compare function for H- strings in WIN32}
{$ENDIF}
{.Z+}
{---Huge memory routines---}
function HugeCompressRLE(const InBuffer; InLen : Longint;
var OutBuffer) : Longint;
{-Run length encode a buffer}
function HugeDecompressRLE(const InBuffer; InLen : Longint;
var OutBuffer; OutLen : LongInt) : Longint;
{-Run length decode a buffer}
procedure HugeFillChar(var Dest; Count : Longint; Value : Byte);
{-Fill huge memory block with byte value}
procedure HugeFillStruc(var Dest; Count : Longint;
const Value; ValSize : Cardinal);
{-Fill huge memory block with structure value}
procedure HugeMove(const Src; var Dest; Count : LongInt);
{-Copy huge memory block to another}
procedure HugeGetMem(var P : Pointer; Size : LongInt);
{-Get huge memory block allocation}
procedure HugeFreeMem(var P : Pointer; Size : LongInt);
{-Free huge memory block allocation}
{.Z-}
{---General purpose character manipulation---}
function Upcase(C : AnsiChar) : AnsiChar;
{-Return the uppercase of a character. Provides international character
support.}
function LoCase(C : AnsiChar) : AnsiChar;
{-Return the lowercase of a character. Provides international character
support.}
{---General comparison and searching---}
function CompareLetterSets(Set1, Set2 : LongInt) : Cardinal;
{-Return the sum of the values of the letters common to Set1 and Set2.}
function CompStruct(const S1, S2; Size : Cardinal) : Integer;
{-Compare two fixed size structures.}
function Search(const Buffer; BufLength : Cardinal; const Match;
MatLength : Cardinal; var Pos : Cardinal) : Boolean;
{-Search a buffer for the specified pattern of bytes.}
function SearchUC(const Buffer; BufLength : Cardinal; const Match;
MatLength : Cardinal; var Pos : Cardinal) : Boolean;
{-Search a buffer for a specified pattern of bytes. This search is not case
sensitive.}
{---Miscellaneous---}
{.Z+}
function IsOrInheritsFrom(Root, Candidate : TClass) : boolean;
{-Return true if the classes are equal or Candidate is a descendant of Root}
procedure RaiseContainerError(Code : longint);
{-Internal routine: raise an exception for a container}
procedure RaiseContainerErrorFmt(Code : Longint; Data : array of const);
{-Internal routine: raise an exception for a container}
function ProductOverflow(A, B : LongInt) : Boolean;
{-Return True if A*B exceeds MaxLongInt}
{$IFNDEF HStrings}
function StNewStr(S : string) : PShortString;
{-Allocate a short string on the heap}
procedure StDisposeStr(PS : PShortString);
{-Deallocate a short string from the heap}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -