Post by FonsI can't find the BDE32.pas. Any sites ?
unit BDE32;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, Registry;
type
TBDE32 = class(TComponent)
private
FUsingCFG: Boolean;
FLocalShare: Boolean;
FPdxNetDir: String;
FMaxBufSize, FMaxFileHandles, FMemSize, FSharedMemSize: integer;
function GetPaths(var CF: string; var DLLP: string): boolean;
procedure writeToCFG(Item: string; Val: string);
function ReadFromCFG(Item: string; DefStr: string): string;
protected
{ Protected declarations }
public
constructor Create(AOwner:TComponent); override;
published
property LocalShare: boolean read FLocalShare write FLocalShare;
property PdxNetDir: String read FPdxNetDir write FPdxNetDir;
property MaxBufSize: integer read FMaxBufSize write FMaxBufSize;
property MaxFileHandles: integer read FMaxFileHandles write
FMaxFileHandles;
property MemSize: integer read FMemSize write FMemSize;
property SharedMemSize: integer read FSharedMemSize write
FSharedMemSize;
procedure WriteSettings;
procedure ReadSettings;
end;
function FilePos(FileName, What: string; startFrom: integer):integer;
procedure Register;
implementation
constructor TBDE32.Create(AOwner:TComponent);
var
ConfigFile, DLLPath: string;
begin
inherited Create(AOwner);
with TRegistry.create do begin
Rootkey := HKEY_LOCAL_MACHINE;
if not
(OpenKey('SOFTWARE\BORLAND\DATABASE ENGINE', false)
and FileExists(ReadString('DLLPATH') + '\idapi32.dll'))
then begin
if GetPaths(ConfigFile, DLLPath) then begin
Rootkey := HKEY_LOCAL_MACHINE;
OpenKey('SOFTWARE\BORLAND\DATABASE ENGINE', True);
WriteString('CONFIGFILE01', ConfigFile);
WriteString('DLLPATH', DLLPath);
WriteString('RESOURCE', '0009');
WriteString('SAVECONFIG', 'WIN32');
WriteString('UseCount', '15');
end
else begin
ShowMessage('Please put BDE files in ' +
ExtractFilePath(application.ExeName) + 'BDE');
halt;
end;
end;
Free;
end;
ReadSettings;
end;
procedure TBDE32.ReadSettings;
begin
FPdxNetDir := ReadFromCFG('NET DIR', 'G:\');
FLocalShare := ReadFromCFG('LOCAL SHARE', 'FALSE') = 'TRUE';
FMaxBufSize := StrToInt(ReadFromCFG('MAXBUFSIZE', '2048'));
FMaxFileHandles := StrToInt(ReadFromCFG('MAXFILEHANDLES', '48'));
FMemSize := StrToInt(ReadFromCFG('MEMSIZE', '16'));
FSharedMemSize := StrToInt(ReadFromCFG('SHAREDMEMSIZE', '2048'));
end;
procedure TBDE32.WriteSettings;
begin
if FLocalShare then writeToCFG('LOCAL SHARE', 'TRUE')
else writeToCFG('LOCAL SHARE', 'FALSE');
writeToCFG('NET DIR', FPdxNetDir);
writeToCFG('MAXBUFSIZE', IntToStr(FMaxBufSize));
writeToCFG('MAXFILEHANDLES', IntToStr(FMaxFileHandles));
writeToCFG('MEMSIZE', IntToStr(FMemSize));
writeToCFG('SHAREDMEMSIZE', IntToStr(FSharedMemSize));
end;
procedure TBDE32.writeToCFG(Item: string; Val: string);
Var
CFGFile, TempFile: string;
CFGStream, TempStream: TFileStream;
FoundPos1, FoundPos2: integer;
myBuf: array[0..255] of char;
begin
with TRegistry.create do begin
Rootkey := HKEY_LOCAL_MACHINE;
OpenKey('SOFTWARE\BORLAND\DATABASE ENGINE', false);
CFGFile := ReadString('CONFIGFILE01');
Free;
end;
TempFile := CFGFile + '2';
FoundPos1 := FilePos(CFGFile, Item, 0);
if FoundPos1 > 0 then begin
FoundPos2 := FilePos(CFGFile, #0, FoundPos1 + Length(Item) +
3);
CFGStream := TFileStream.Create(CFGFile, fmOpenRead);
TempStream := TFileStream.Create(TempFile, fmOpenWrite or
fmCreate);
TempStream.CopyFrom(CFGStream, FoundPos1 + Length(Item) + 2);
StrPCopy(MyBuf, Val);
TempStream.Write(MyBuf, length(Val));
CFGStream.Seek(FoundPos2 - 1, soFromBeginning);
TempStream.CopyFrom(CFGStream, CFGStream.Size - FoundPos2 +
1);
TempStream.Free;
CFGStream.Free;
end;
DeleteFile(CFGFile);
RenameFile(TempFile, CFGFile);
end;
function TBDE32.ReadFromCFG(Item: string; DefStr: string): string;
Var
CFGFile: string;
FoundPos1, FoundPos2: integer;
MyFile: TextFile;
MyStr: string;
begin
with TRegistry.create do begin
Rootkey := HKEY_LOCAL_MACHINE;
OpenKey('SOFTWARE\BORLAND\DATABASE ENGINE', false);
CFGFile := ReadString('CONFIGFILE01');
Free;
end;
if FileExists(CFGFile) then begin
AssignFile(MyFile, CFGFile);
Reset(MyFile);
ReadLn(MyFile, MyStr);
CloseFile(MyFile);
FoundPos1 := Pos(Item, MyStr);
if FoundPos1 > 0 then begin
Delete(MyStr, 1, FoundPos1 + Length(Item) + 2);
foundPos2 := Pos(#0, MyStr);
Result := Copy(MyStr, 0, FoundPos2 + 1);
end
else result := DefStr;
end
else result := DefStr;
end;
function FilePos(FileName, What: string; startFrom: integer): integer;
var
MyStr: string;
MyFile: TextFile;
begin
if FileExists(FileName) then begin
AssignFile(MyFile, FileName);
Reset(MyFile);
ReadLn(MyFile, MyStr);
Delete(MyStr, 1, StartFrom);
Result := StartFrom + Pos(What, MyStr);
CloseFile(MyFile);
end
else result := 0;
end;
function TBDE32.GetPaths(var CF: string; var DLLP: string): boolean;
var
AppDir: string;
begin
AppDir := ExtractFilePath(Application.ExeName);
if FileExists(AppDir + 'idapi32.cfg') then CF := AppDir +
'idapi32.cfg';
if FileExists(AppDir + 'idapi32.dll') then DLLP := Copy(AppDir,
1, Length(AppDir) - 1);
if FileExists(AppDir + 'BDE\idapi32.cfg') then CF := AppDir +
'BDE\idapi32.cfg';
if FileExists(AppDir + 'BDE\idapi32.dll') then DLLP := AppDir +
'BDE';
if FileExists('c:\program files\borland\common
files\BDE\idapi32.cfg') then CF := 'c:\program files\borland\common
files\BDE\idapi32.cfg';
if FileExists('c:\program files\borland\common
files\BDE\idapi32.dll') then DLLP := 'c:\program files\borland\common
files\BDE';
Result := FileExists(CF) and FileExists(DLLP + '\idapi32.dll');
end;
procedure Register;
begin
RegisterComponents('DataAccess', [TBDE32]);
end;
end.