Unit AUtility

++ {Renamed from Utility.pas 6/20/1998 Paul Rice to avoid conflicts with others' work.

Classes

EApiError - Exception classes

Functions

AddBkSlash - Assure that all directories in path exist.
AddFileExt - Raises an EApiError with the specified system error code } { File utility functions
ApiCheck - System functions

Functions
ApiError - If Error is True, this function raises an EApiError with the last error code and message
AssurePath - Add extension to file name, deleting old extension.
ExpandEnvironmentStr - Read variable from environment block of the calling process
ForceFileExt - Add extension to file name if the file name does not already contain an extension.
GetComputerNameStr - Retrieve the user name of the current thread.
GetEnvironmentVarStr - Write list of strings to stream } { System functions
GetSystemDirectoryStr - Retrieve the path of the directory designated for temporary files
GetTempFileNameStr - Retrieve the computer name of the current system.
GetTempPathStr - Generate a unique temporary file name.
GetTicks - Returns an empty tick value
GetUserNameStr - Expands variables in Str to their equivalent environment variable values
LongSub - Retrieve system directory } { Miscellaneous low-level functions
NullTicks -
RemBkSlash - Returns S with backslash added
ReplaceString - Compares two strings using Unix-like wild cards.
StrCompareWildCards - Removes double quotes ("") from string Str
StreamReadLn - Read string from stream
StreamReadString - Write string Str to stream
StreamReadStrings - Write string to stream
StreamWrite - Write crlf-terminated line to stream
StreamWriteLn - Read crlf-terminated line from stream
StreamWriteString - Returns S with backslash removed} { Stream utilities
StreamWriteStrings - Read list of strings written with StreamWriteStrings from stream
StrGetWord -
StrWordCount - Extracts word number N from string S.
StrWordPos - Returns number of words in S
TicksSub - Get current tick count.
TicksToInt - Subtract B ticks from A
TicksToSec - Convert ticks to integer
UnquoteStr - Returns the character position of a word in S

Types

TCharSet
TTicks
TWordOptions

Constants

Variables


Functions


function AddBkSlash (const S : string) : string;

Assure that all directories in path exist. Equivalent to the ForceDirectories function in the Borland FileCtrl unit } { File string functions

function AddFileExt (const S, Ext : string) : string;

Raises an EApiError with the specified system error code } { File utility functions

procedure ApiCheck (Result : Boolean);

System functions

Functions


procedure ApiError (ErrorCode : Longint);

If Error is True, this function raises an EApiError with the last error code and message

function AssurePath (const Path : string) : Boolean;

Add extension to file name, deleting old extension. Equivalent to the ChangeFileExt procedure in SysUtils, except Ext must not contain period

function ExpandEnvironmentStr (const Str : string) : string;

Read variable from environment block of the calling process

function ForceFileExt (const S, Ext : string) : string;

Add extension to file name if the file name does not already contain an extension. Ext must not contain period character

function GetComputerNameStr : string;

Retrieve the user name of the current thread. This is the name of the user currently logged onto the system.

function GetEnvironmentVarStr (const VarName : string) : string;

Write list of strings to stream } { System functions

function GetSystemDirectoryStr : string;

Retrieve the path of the directory designated for temporary files

function GetTempFileNameStr (const Path, Prefix : string; Unique : Longint) : string;

Retrieve the computer name of the current system. This name is established at system startup, when it is initialized from the registry

function GetTempPathStr : string;

Generate a unique temporary file name. If successful, the file is also created with zero length. The resulting file name is the concatenation of specified path and prefix strings, a hexadecimal string formed from a specified integer, and the .TMP extension. If Unique is zero, a random number is used for the integer value; otherwise this value is used

function GetTicks : TTicks;

Returns an empty tick value

function GetUserNameStr : string;

Expands variables in Str to their equivalent environment variable values

function LongSub (A, B : Longint) : Longint;

Retrieve system directory } { Miscellaneous low-level functions

function NullTicks : TTicks;


function RemBkSlash (const S : string) : string;

Returns S with backslash added

function ReplaceString (const Str, SubStr, NewStr : string) : string;

Compares two strings using Unix-like wild cards. Both A and B may contain the wild cards * and ?

function StrCompareWildCards (const A, B : string) : Boolean;

Removes double quotes ("") from string Str

function StreamReadLn (Stream : TStream) : string;

Read string from stream

function StreamReadString (Stream : TStream) : string;

Write string Str to stream

procedure StreamReadStrings (Stream : TStream; Strings : TStrings);

Write string to stream

procedure StreamWrite (Stream : TStream; Str : string);

Write crlf-terminated line to stream

procedure StreamWriteLn (Stream : TStream; Str : string);

Read crlf-terminated line from stream

procedure StreamWriteString (Stream : TStream; const Str : string);

Returns S with backslash removed} { Stream utilities

procedure StreamWriteStrings (Stream : TStream; Strings : TStrings);

Read list of strings written with StreamWriteStrings from stream

function StrGetWord (const S : string; N : Integer; const Delims : TCharSet; const Options : TWordOptions) : string;


function StrWordCount (const S : string; const Delims : TCharSet; const Options : TWordOptions) : Integer;

Extracts word number N from string S. Delims specify the characters used to delimit words

function StrWordPos (const S : string; N : Integer; const Delims : TCharSet; const Options : TWordOptions) : Integer;

Returns number of words in S

function TicksSub (A, B : TTicks) : TTicks;

Get current tick count. Maps to GetTickCount

function TicksToInt (Ticks : TTicks) : Integer;

Subtract B ticks from A

function TicksToSec (Ticks : TTicks) : Integer;

Convert ticks to integer

function UnquoteStr (const Str : string) : string;

Returns the character position of a word in S

Types


TCharSet = set of Char
Types
TTicks = record
L : Word;
H : Word;
end;
Evaluates the unsigned integer expression A-B, returning the result } { Timing functions. The tick routines avoid problems with 32-bit integers in Delphi, providing a separate type for storing the tick value
TWordOptions = set of
    (
      woNoSkipQuotes,
      woNoConsecutiveDelims
    )
Convert ticks to seconds } { String utilities

Constants


Variables