Unit HomeTool

Alek's home tools. History: ~~~~~~~~ [+] -- added; [*] -- fixed; [-] -- removed; 13 December 1997: [+] function SelectFolder(aHandle: tHandle; const aRoot, aMsg: string): string; [+] function GetRegStr(const aAppName, aKeyName, aDefValue: string): string; [+] procedure SetRegStr(const aAppName, aKeyName, aKeyValue: string); 21 December 1997: [+] tFileMappingRecord; [+] function NewFileMapping(const aFileName: string; var aFMR: tFileMappingRecord): Boolean; [+] function FreeFileMapping(var aFMR: tFileMappingRecord): Boolean; [+] function SeekBuf(Buf1: Pointer; Buf1Size: Integer; Buf2: Pointer; Buf2Size: Integer): Integer; [+] function SeekStr(aBuf: Pointer; aBufSize: Integer; const aStr: string; IgnoreCase: Boolean): Integer; 25/26 December 1997: [*] bug in SeekStr; 26 December 1997: [*] GetRegStr now will not create key if it doesn't exists; 12 JAN 1998 [+] finction AddBackSlash(const aPath: string): string; 27 JAN 1998 [+] function AskYN(const aMsg: string): Boolean; [+] function AskYNC(const aMsg: string): Integer; 04 MAR 1998 [+] function Str2Int(const aStr: string; aDefValue: Integer): Integer; 15? MAR 1998 [+] function ReadTextFile(const aFileName: string): string; [+] function AddTextToFile(const aFileName, aText: string; AddCRLF: Boolean): Boolean; 05 APR 1998 [*] another bug in SeekStr -- wrong detection of buffer's end [+] function ParseString(const aString: string; aVChar: Char; aValues: tStrings); 12 APR 1998 [+] procedure SetRegInt(const aAppName, aKeyName: string; aKeyValue: Integer); [+] function GetRegInt(const aAppName, aKeyName: string; aDefValue: Integer): Integer; 20 APR 1998 [+] function Min(A, B: Integer): Integer; [+] function Max(A, B: Integer): Integer; 22 APR 1998 [*] Trim added in Str2Int for universality 30 APR 1998 [+] function Date2Str(aDate: tDateTime): string; 04 MAY 1998 [+] function RegLoadFont(aFont: tFont; const aRegAppName: string): Boolean; [+] function RegSaveFont(aFont: tFont; const aRegAppName: string): Boolean; 05 MAY 1998 [+] procedure RegSaveControl(aControl: tControl; const anAppName: string); [+] function RegLoadControl(aControl: tControl; const anAppName: string): Boolean;

Classes

Functions

AddBackSlash - correctly adds '\' to the given path: C:\temp\ => C:\temp\ C:\temp => C:\temp\ C:\ => C:\ C: => C: C:\temp/ => C:\temp/
AddTextToFile - adds string to text file (optionally adding CR LF after inserted line
AskYN - shows message dialog with [Yes] [No] buttons
AskYNC - show message dialog with [Yes] [No] [Cancel] buttons resturns: mrYes = Yes; mrNo = No; mrCancel = Cancel
Date2Str -
FreeFileMapping - this function frees up resources taken by NewFileMapping
GetRegInt - like GetRegStr but works with integer
GetRegStr - may change to something like HKEY_LOCAL_MACHINE used to read value from registry; aAppName -- application title (i.
Hex2Int -
Max - if A > B then result is A, else B

blah.
Min - if A < B then result is A, else B

blah.
NewFileMapping - creates new file mapping (contents of file can be accessed by pointer); aFileName -- file name to create mapping of; aFMR -- if Result is true you can use aFMR.
ParseString - will parse given string like this: // aString = Welcome to %NAME%, dear %USER% aVChar = % aValues[0] = 'NAME=Alek' aValues[1] = 'USER=Local' // result: Welcome to Alek, dear Local
ReadTextFile - just reads all text from file
RegLoadControl -
RegLoadFont -
RegSaveControl -
RegSaveFont -
SeekBuf - I have no time to test this function

WARNING: I don't test this function yet!
SeekStr - fast way to seek a substring in string (or any buffer) aBuf -- pointer to buffer to seek in; aBufSize -- size of buffer; aStr -- substring to seek; IgnoreCase -- ignore or not the case (international characters not supported!); (for binary seeking set this parameter to False); Result -- position in aBuf of firt occurance of aStr or -1 if none; (0 means start of buffer);
SelectFolder - aHandle -- handle of the owner window for the dialog box.
SetRegInt - like SetRegStr but works with integer
SetRegStr - used to write value to registry; aAppName -- application title (i.
Str2Int - safetly converts a string to Integer; if error occured, then returns aDefValue

Types

pBytes
tBytes
tFileMappingRecord

Constants

regRoot
regRootKey

Variables


Functions


function AddBackSlash(const aPath: string): string;

correctly adds '\' to the given path: C:\temp\ => C:\temp\ C:\temp => C:\temp\ C:\ => C:\ C: => C: C:\temp/ => C:\temp/

function AddTextToFile(const aFileName, aText: string; AddCRLF: Boolean): Boolean;

adds string to text file (optionally adding CR LF after inserted line

function AskYN(const aMsg: string): Boolean;

shows message dialog with [Yes] [No] buttons

function AskYNC(const aMsg: string): Integer;

show message dialog with [Yes] [No] [Cancel] buttons resturns: mrYes = Yes; mrNo = No; mrCancel = Cancel

function Date2Str(const aDate: tDateTime{; const aMask: string}): string;


function FreeFileMapping(var aFMR: tFileMappingRecord): Boolean;

this function frees up resources taken by NewFileMapping

function GetRegInt(const aAppName, aKeyName: string; aDefValue: Integer): Integer;

like GetRegStr but works with integer

function GetRegStr(const aAppName, aKeyName, aDefValue: string): string;

may change to something like HKEY_LOCAL_MACHINE used to read value from registry; aAppName -- application title (i.e. 'ASWS', 'Project1', ...); it will be used to create registry key name: [HKEY_CURRENT_USER\regRoot\aAppName] aKeyName -- name of registry key to get (i.e. 'Settings', 'Form1\Left', ...); (do not add '\' after key name!); aDefValue -- will be returned if key (aKeyName) does not exists; NOTE: key will NOT be created, use SetRegStr to do this.

function Hex2Int(const S: string): Integer;


function Max(A, B: Integer): Integer;

if A > B then result is A, else B

blah...blah


function Min(A, B: Integer): Integer;

if A < B then result is A, else B

blah...blah


function NewFileMapping(const aFileName: string; var aFMR: tFileMappingRecord): Boolean;

creates new file mapping (contents of file can be accessed by pointer); aFileName -- file name to create mapping of; aFMR -- if Result is true you can use aFMR.fFileBase to access file contents

function ParseString(const aString: string; aVChar: Char; aValues: tStrings): string;

will parse given string like this: // aString = Welcome to %NAME%, dear %USER% aVChar = % aValues[0] = 'NAME=Alek' aValues[1] = 'USER=Local' // result: Welcome to Alek, dear Local

function ReadTextFile(const aFileName: string): string;

just reads all text from file

function RegLoadControl(aControl: tControl; const anAppName: string): Boolean;


function RegLoadFont(aFont: tFont; const aRegAppName: string): Boolean;


procedure RegSaveControl(aControl: tControl; const anAppName: string);


function RegSaveFont(aFont: tFont; const aRegAppName: string): Boolean;


function SeekBuf(Buf1: Pointer; Buf1Size: Integer; Buf2: Pointer; Buf2Size: Integer): Integer;

I have no time to test this function

WARNING: I don't test this function yet!


function SeekStr(aBuf: Pointer; aBufSize: Integer; const aStr: string; IgnoreCase: Boolean): Integer;

fast way to seek a substring in string (or any buffer) aBuf -- pointer to buffer to seek in; aBufSize -- size of buffer; aStr -- substring to seek; IgnoreCase -- ignore or not the case (international characters not supported!); (for binary seeking set this parameter to False); Result -- position in aBuf of firt occurance of aStr or -1 if none; (0 means start of buffer);

function SelectFolder(aHandle: tHandle; const aRoot, aMsg: string): string;

aHandle -- handle of the owner window for the dialog box. Can be 0; aRoot -- location of the "root" folder to browse from. Only the specified by aRoot folder and its subfolders appear in the dialog box. This member can be '', and in that case, the name space root (the desktop folder) is used; aMsg -- string that is displayed above the tree view control in the dialog box. This string can be used to specify instructions to the user; Result -- if user chooses the Cancel button in the dialog box, the return value is '', else result is selected folder;

WEIRD! Is this new Microsofto style?


procedure SetRegInt(const aAppName, aKeyName: string; aKeyValue: Integer);

like SetRegStr but works with integer

procedure SetRegStr(const aAppName, aKeyName, aKeyValue: string);

used to write value to registry; aAppName -- application title (i.e. 'ASWS', 'Project1', ...); it will be used to create registry key name: [HKEY_CURRENT_USER\regRoot\aAppName] aKeyName -- name of registry key to set (i.e. 'Settings', 'Form1\Left', ...); aKeyValue -- value to be set; if key doesn't exists, it will be created.

function Str2Int(const aStr: string; aDefValue: Integer): Integer;

safetly converts a string to Integer; if error occured, then returns aDefValue

Types


pBytes = ^tBytes

tBytes = array[0..High(Integer)-16] of Byte;

tFileMappingRecord = record
fFileHandle : tHandle;
fFileMapping : tHandle;
end;
this record is used to store and access created file mappings

Constants

regRoot = 'Software\HammerSoft\Projects\'

change this in runtime, if you want

regRootKey = HKEY_CURRENT_USER


Variables