Program to create aliases for Absolute DB databases by Johan Keizer
What I am missing in absolute database is the use of aliases like in bde.
To overcome this, I wrote a little program to create aliases and some (2)
functions to retrieve them.
?
The program can create the aliases and can display a help screen, from
which the retrieve functions can be cut to paste them into the application,
that needs them.
?
When you like this, you may use the source and/or program for whatever you
want.
For completeness, this is the text of the help:
?
? ? __________________
?
? Help for ABS_Alias ? __________________
?
? Contents:
?
? ? ? 1 Info ? ? ? 2 Syntax ? ? ?
3 Buttons ? ? ? 4 Functions source
?
? 1 Info:
?
? ? ? This program is used to specify aliases for 'Absolute
Database' database ? ? ? files. An alias is usefull to keep
your program independant from the place ? ? ? of the
database. ? ? ? This program uses function
GetABSAliasFilename to retrieve or create ? ? ? the file
that contains the alias information. GetABSAliasFilename ? ? ?
creates an empty file when it did not exist before. Click the 'Cancel' ? ? ?
button and this file will be deleeted.
?
? ? ? The file is created in or retrieved from %Local
Settings%\ABS_ALias.txt or ? ? ? when the registry key for
'Local Settings' (unexpectedly) does not exist the ? ? ?
file is created in or retrieved from C:\ABS_ALias.txt.
?
? ? ? In your program use the function
'GetABSDbByAlias(Alias)' to get the ? ? ? databasefilename
for your alias. Function GetABSDbByAlias also calls ? ? ?
function GetABSAliasFilename to get the right file. ? ? ?
When the alias is not found in this file, this function returns a ? ? ?
question mark (?), on which you can act as desirable.
?
? ? ? The sources of functions GetABSAliasFilename and
GetABSDbByAlias are listed ? ? ? in "4 Functions source"
below. You may cut these functions from this ? ? ? helpfile
with +C to the clipboard and paste it into your source file.
?
? 2 Syntax:
?
? ? ? The syntax of this file is only inspected by function
GetABSDbByAlias ? ? ? and not by this program. The lines in
the file are inspected by ? ? ? GetABSDbByAlias whith below
rules and no errormessage is given !
?
? ? ? Each line in the aliasfile may contain one of the
following: ? ? ? ? ? - No data or only spaces. ? ? ? ? ? ? ? ? ?
These lines are skipped. ? ? ? ? ? - Data starting
with an asterix '*'. ? ? ? ? ? ? ? ? ?
These lines are treated as comment and will be skipped. ? ? ? ? ? ? ? ? ?
Spaces before the asterix are allowed. ? ? ? ? ? -
Data without an equal sign. ? ? ? ? ? ? ? ? ?
These lines are skipped also. ? ? ? ? ? - A
statement in the form alias=databasefilename. ? ? ? ? ? ? ? ? ?
Example: mydb=c:\my dbdir\my db.abs ? ? ? ? ? ? ? ? ?
Spaces around alias and databasefilename are trimmed, although ? ? ? ? ? ? ? ? ?
the spaces within the databasefilename are kept. ? ? ? ? ? ? ? ? ?
So ' mydb? =? c:\my dbdir\my db.abs? ' is (without the
quotes) ? ? ? ? ? ? ? ? ? a valid
substitute for above example. ? ? ? ? ? ? ? ? ?
First match will be used.
?
? 3 Buttons:
?
? ? ? in "File mode": ? ? ? ? ? Ok:? ? ? ?
- Save this file. ? ? ? ? ? ? ? ? ? ? ? ? ?
- If 'file to save' is empty or only contains empty lines, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
then delete it. ? ? ? ? ? ? ? ? ? ? ? ? ?
- Exit program. ? ? ? ? ? Cancel: - Do not save this
file. ? ? ? ? ? ? ? ? ? ? ? ? ?
- If the file was initially empty delete it. ? ? ? ? ? ? ? ? ? ? ? ? ?
- Exit program. ? ? ? ? ? Help:? ? - Give
usefull information. Go to "Help mode"
?
? ? ? in "Help mode": ? ? ? ? ?
Return: - Leave "Help mode" and return to "File mode".
?
? 4 Functions source:
?
? ? ? function? GetABSAliasFilename: string; ? ? ?
var Reg: TRegistry; TS: TStringList; ? ? ? begin ? ? ? ? ?
Reg? ? ? ? ? ? ? ? ? ? :=
TRegistry.Create; ? ? ? ? ? Reg.RootKey? ?
:= HKEY_CURRENT_USER; ? ? ? ? ? Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\'+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
'Shell Folders',False); ? ? ? ? ? try ? ? ? ? ? ? ?
result := Reg.ReadString('Local Settings')+'\ABS_ALias.txt'; ? ? ? ? ?
except ? ? ? ? ? ? ? result := 'C:\ABS_ALias.txt'; ? ? ? ? ?
end; ? ? ? ? ? Reg.CloseKey; Reg.Free; ? ? ? ? ?
if not FileExists(result) then ? ? ? ? ? ? ?
begin // Create empty file ? ? ? ? ? ? ? ? ?
TS := TStringList.Create; TS.SaveToFile(result); TS.Free; ? ? ? ? ? ? ?
end; ? ? ? end;
?
? ? ? function? GetABSDbByAlias(Alias: string): string; ? ? ?
var TS: TStringList; i, p: integer; LineIn, AliasIn, DBIn: string; ? ? ?
begin ? ? ? ? ? Alias := lowercase(Alias); result :=
'?'; ? ? ? ? ? TS := TStringList.Create;
TS.LoadFromFile(GetABSAliasFilename); ? ? ? ? ? for
i := 0 to TS.Count-1 do ? ? ? ? ? begin ? ? ? ? ? ? ?
LineIn? ? ? ? ? ? ? ? ? ? ? ?
:= lowercase(trim(TS[i])); ? ? ? ? ? ? ? if
LineIn=''? ? ? ? ? ? then continue; ? ? ? ? ? ? ?
if LineIn[1]='*'? ? then continue; ? ? ? ? ? ? ?
p? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
:= pos('=',LineIn); ? ? ? ? ? ? ? if p=0? ? ? ? ? ? ? ? ? ? ? ?
then continue; ? ? ? ? ? ? ? AliasIn? ? ? ? ? ? ? ? ? ? ?
:= trim(copy(LineIn,1,p-1)); ? ? ? ? ? ? ?
DBIn? ? ? ? ? ? ? ? ? ? ? ? ? ?
:= trim(copy(LineIn,p+1,255)); ? ? ? ? ? ? ?
if Alias=AliasIn? ? then begin result := DBIn; break; end; ? ? ? ? ?
end; ? ? ? ? ? TS.Free; ? ? ? end;
Kind regards,
Johan Keizer
Koedijk
The Netherlands |