Unit MoreUtil

Classes

Functions

BatchRun - Imports sw_restore
BooleanToYN - Returns true if running progran started with 'B' or 'b' on the command line

BatchRun
CanSave - Converts boolean variable to string 'Yes' or 'No'

BooleanToYN
ChangePath - Returns true when - the file does not (yet) exist - the file exists but the user accepts that it is going to be overwritten - the user has changed the filename (var!) and has ok'd it

CanSave
ClearDir - changes the path of a filespecification into 'newpath'

ChangePath
CopyFile - Deletes the files in an existing directory

ClearDir
CopyFileOverwrite - Copies file 'srcfilename' to 'destfilename'

CopyFile
CountChar - Copies file 'srcfilename' to 'destfilename'.
CountLines - Counts the number of times a character occurs in a string

CountChar
DirectoryExists - Counts the number of lines in a text file

CountLines
Elapsed - Checks whether or not a directory exists.
ExtendedVersionStr - Returns runtime in seconds

Elapsed
FatalError - Returns a string containing the name and the date of creation of the running program

ExtendedVersionStr
FileNameSplit - Produces window with Str as message.
FindCommonStrings - Returns separate parts of a file specification

FileNameSplit
FindString - Returns in CommonStrings the stings that are present in both List1 and List2

FindCommonStrings
ForceBackslash - Frees the object that's pointed to by o AND sets o to nil, so that it can't be Destroyed a second time (which would cause a GPF)

FreeObject
FreeList - Finds substring in a string; options e.
FreeObject - Frees list List the objects it contains

FreeList
GetIniPath - Adds a default backslash to a directory name if not already present

ForceBackslash
GetIniString - Finds path in .
LeftAlign - Finds string value in .
LeftStr - Returns a string with length Count, with s at the left and padded with spaces to the right

LeftAlign
OpenIniFile - Returns a string with the first 'count' characters of s

LeftStr
ReplaceChars - Opens the ini file of the 'current application'.
RightAlign - Replaces characters in string that are equal to FromCh with characters ToCh

ReplaceChars
RightStr - Returns a string with length Count, with s at the right and padded with spaces to the left

RightAlign
RunDosCommand - Returns a string with the last 'count' characters of s

RightStr
RunProgram - Runs Dos command as if it were started from the command line, explicitly calling command.
ShowMessage - Runs program as if it were started from the command line

RunProgram
SpaceStr - Same as Dialogs' ShowMessage, but sets the cursor to crDefault before displaying the dialog and sets it back to what it was afterwards

ShowMessage
SplitStringAt - returns string containing n spaces (#32)

SpaceStr
StrToDateTime - Splits string at first splitchar; if splitchar is not found, firstpart:=str; secondpart:=''

SplitStringAt
StrToFloat - Same as SysUtils.
ThreeDigitStr - See Help on StrToFloat for specification.
Trim - Makes a string of three digits representing the number 'n'; the number ought to lie in the interval [0, 999]

threedigitstr
TwoDigitStr - Eliminates leading and trailing spaces from a string

Trim
VersionStr - Makes a string of two digits representing the number 'n'; the number ought to lie in the interval [0, 99]

Twodigitstr
WarningMessage - Returns a string that represents the date of creation of the executable file of the program that's being executed

VersionStr
WithoutBackslash - Produces window with Str as message.

Types

string12
string2
string4
string8
TFindOption
TFindOptions

Constants

CR
CRLF
LF
Space
Tab

Variables

StartTime
StopTime
WarningForm


Functions


function BatchRun: boolean;

Imports sw_restore

function BooleanToYN(Check: boolean): string;

Returns true if running progran started with 'B' or 'b' on the command line

BatchRun


function CanSave(var Filename: String): Boolean;

Converts boolean variable to string 'Yes' or 'No'

BooleanToYN


procedure ChangePath(oldfilespec: string; newpath: string; var newfilespec: string);

Returns true when - the file does not (yet) exist - the file exists but the user accepts that it is going to be overwritten - the user has changed the filename (var!) and has ok'd it

CanSave


procedure ClearDir(Dir: string);

changes the path of a filespecification into 'newpath'

ChangePath


procedure CopyFile(srcfilename, destfilename: String);

Deletes the files in an existing directory

ClearDir


procedure CopyFileOverwrite(srcfilename, destfilename: String);

Copies file 'srcfilename' to 'destfilename'

CopyFile


procedure CountChar(s: String; ch: Char; var N: Integer);

Copies file 'srcfilename' to 'destfilename'. Gives no warning if destfilename already exists

CopyFileOverwrite


procedure CountLines(fname: String; var Nlines: Longint);

Counts the number of times a character occurs in a string

CountChar


function DirectoryExists(dir: String): Boolean;

Counts the number of lines in a text file

CountLines


function Elapsed: string;

Checks whether or not a directory exists. The current directory remains current

DirectoryExists


function ExtendedVersionStr: String;

Returns runtime in seconds

Elapsed


procedure FatalError(MessageStr: string);

Returns a string containing the name and the date of creation of the running program

ExtendedVersionStr


procedure FileNameSplit(Spec: string; var path, name, ext:string);

Produces window with Str as message. Stops calling program.

FatalError


procedure FindCommonStrings(List1, List2: TStringlist; var CommonStrings: TStringlist);

Returns separate parts of a file specification

FileNameSplit


function FindString(substr, s: String; options: TFindOptions): Integer;

Returns in CommonStrings the stings that are present in both List1 and List2

FindCommonStrings


function ForceBackslash(const DirName: String): String;

Frees the object that's pointed to by o AND sets o to nil, so that it can't be Destroyed a second time (which would cause a GPF)

FreeObject


procedure FreeList(var List: TList);

Finds substring in a string; options e.g.: whole word; case-sensitive

FindString


procedure FreeObject(var o);

Frees list List the objects it contains

FreeList


procedure GetIniPath(section, varname: String; var dir: String);

Adds a default backslash to a directory name if not already present

ForceBackslash


procedure GetIniString(section, varname: String; var result: String);

Finds path in .INI file. See GetIniString, but the found string must be a path.

GetIniPath


function LeftAlign(s: String; count: Integer): String;

Finds string value in .INI file

GetIniPath


function LeftStr(s: String; count: Integer): String;

Returns a string with length Count, with s at the left and padded with spaces to the right

LeftAlign


procedure OpenIniFile(var Inifile: TIniFile);

Returns a string with the first 'count' characters of s

LeftStr


procedure ReplaceChars(var S: String; FromCh, ToCh: Char);

Opens the ini file of the 'current application'. It is assumed to be at the same location as the executable

OpenIniFile


function RightAlign(s: String; count: Integer): String;

Replaces characters in string that are equal to FromCh with characters ToCh

ReplaceChars


function RightStr(s: String; count: Integer): String;

Returns a string with length Count, with s at the right and padded with spaces to the left

RightAlign


procedure RunDosCommand(CmdLine: String);

Returns a string with the last 'count' characters of s

RightStr


procedure RunProgram(CmdLine: String);

Runs Dos command as if it were started from the command line, explicitly calling command.com

RunDosCommand } (* procedure RunProgram(CmdLine: String); { Runs program as if it were started from the command line } var ExecResult: Integer; Filename: array[0..100] of Char; p, H: Integer; begin { RunProgram } CmdLine := Cmdline + Chr(0); ExecResult := WinExec(@CmdLine[1], sw_restore); if ExecResult < 32 then ShowMessage('Execution of command line' + CRLF + LeftStr(CmdLine, Length(CmdLine)-1) + CRLF + 'failed. Error code:' + IntToStr(ExecResult)); {p := Pos(' ', CmdLine); CmdLine := LeftStr(CmdLine, p-1) + Chr(0);} Application.ProcessMessages; H := GetModuleHandle(@CmdLine[1]); end; { RunProgram }


procedure ShowMessage(message: String);

Runs program as if it were started from the command line

RunProgram


function SpaceStr(n: longint): string;

Same as Dialogs' ShowMessage, but sets the cursor to crDefault before displaying the dialog and sets it back to what it was afterwards

ShowMessage


procedure SplitStringAt(str: String; splitchar: Char; var firstpart, secondpart: String);

returns string containing n spaces (#32)

SpaceStr


function StrToDateTime(S: string): TDateTime;

Splits string at first splitchar; if splitchar is not found, firstpart:=str; secondpart:=''

SplitStringAt


function StrToFloat(const S: string): Extended;

Same as SysUtils.StrToDateTime, but this one also works under Delphi 1 for date of format YY/MM/DD.

StrToDateTime


function ThreeDigitStr(n: Integer): String;

See Help on StrToFloat for specification. This wrapper is needed because for unknown reasons, on some (Win95) systems StrToFloat gives exceptions where it shouldn't

StrToFloat


procedure Trim(var s: String);

Makes a string of three digits representing the number 'n'; the number ought to lie in the interval [0, 999]

threedigitstr


function TwoDigitStr(n: Integer): String;

Eliminates leading and trailing spaces from a string

Trim


function VersionStr: String;

Makes a string of two digits representing the number 'n'; the number ought to lie in the interval [0, 99]

Twodigitstr


procedure WarningMessage(Str: string);

Returns a string that represents the date of creation of the executable file of the program that's being executed

VersionStr


function WithoutBackslash(const DirName: String): String;

Produces window with Str as message. Calling program keeps running.

WarningMessage


Types


string12 = string[12]

string2  = string[2]

string4  = string[4]

string8  = string[8]

TFindOption = (foCaseSensitive, foWholeWord);

TFindOptions = set of TFindOption

Constants

CR = #13

Imports TIniFile

CRLF = CR + LF

Tab character

LF = #10

carriage return character

Space = #32

linefeed character

Tab = #9

space character

Variables

StartTime : TDateTime

For function Elapsed

StopTime : TDateTime

WarningForm : TWarningForm

For accumulation of warnings