 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Glenn Greatwood Guest
|
Posted: Thu Feb 01, 2007 4:03 pm Post subject: check for LocalShare=True |
|
|
Hi
Is it possible for my app to check that Local Share is set to true on
start-up? If so..how...
Thanks for your time
--
Kind Regards
Glenn Greatwood
Key-Data Systems |
|
| Back to top |
|
 |
Bill Todd Guest
|
Posted: Thu Feb 01, 2007 8:16 pm Post subject: Re: check for LocalShare=True |
|
|
Glenn Greatwood wrote:
| Quote: | Hi
Is it possible for my app to check that Local Share is set to true on
start-up? If so..how...
Thanks for your time
|
Use the BDE API function DbiOpenCfgInfoList. See the BDE help file in
your BDE directory and www.borland.com/devsupport/bde/bdeapiex.
--
Bill Todd (TeamB) |
|
| Back to top |
|
 |
Joe Griffin Guest
|
Posted: Fri Feb 02, 2007 3:13 am Post subject: Re: check for LocalShare=True |
|
|
Glenn Greatwood wrote:
| Quote: | Is it possible for my app to check that Local Share is set to true on
start-up? If so..how...
|
As I just posted in b.p.bde
From production code ...
function TMainForm.CheckLocalShare: Boolean;
var
ASYSConfig : SYSConfig;
Reg : TRegistry;
begin
{ Ensure BDE is initialised }
Session.Open;
Reg := TRegistry.Create; // Defaults to HKEY_CURRENT_USER
try
if NOT Reg.OpenKey('Software\Borland\Delphi', False) then
begin
if (DbiGetSysConfig(ASYSConfig) = DbiErr_None) and
not ASYSConfig.bLocalShare then
begin
result := False;
end
else
begin
result := True;
end;
end
else
begin
// Development machine - don't set Local Share
result := True;
end;
finally // wrap up
Reg.CloseKey;
Reg.Free;
end; // try/finally
end;
procedure TMainForm.SetConfigParameter(Param: string; Value: string);
var
hCur: hDBICur;
rslt: DBIResult;
Config: CFGDesc;
Path, Option: string;
Found: boolean;
Temp: array[0..255] of char;
begin
hCur := nil;
Found := False;
Check(DbiInit(nil)); // initialise the BDE
try
if Pos(';', Param) = 0 then
raise EDatabaseError.Create('Invalid parameter passed to function. There must ' +
'be a semi-colon delimited sting passed');
Path := Copy(Param, 0, Pos(';', Param) - 1);
Option := Copy(Param, Pos(';', Param) + 1, Length(Param) - Pos(';', Param));
Check(DbiOpenCfgInfoList(nil, dbiREADWRITE, cfgPERSISTENT, StrPCopy(Temp, Path), hCur));
repeat
rslt := DbiGetNextRecord(hCur, dbiNOLOCK, @Config, nil);
if rslt = DBIERR_NONE then
begin
if StrPas(Config.szNodeName) = Option then
begin
StrPCopy(Config.szValue, Value);
Check(DbiModifyRecord(hCur, @Config, FALSE));
Found := True;
break;
end;
end
else if rslt <> DBIERR_EOF then
Check(rslt);
until rslt <> DBIERR_NONE;
if Found = False then
raise EDatabaseError.Create(Param + ' entry was not found in configuration file');
finally
if hCur <> nil then
Check(DbiCloseCursor(hCur));
Check(DbiExit); // Ensure the changes are saved
end;
end;
Called by:
procedure TMainForm.FormShow(Sender: TObject);
begin
if NOT CheckLocalShare then
begin
// Local Share was not set, so set it and restart
SetConfigParameter('\SYSTEM\INIT\;LOCAL SHARE', 'TRUE');
MsgDlg('In order to improve the robustness of Hot-costing,' + #13 +
'there has been a change to a System setting on your machine.' + #13#13 +
'This program will now close!' + #13#13 +
'Please restart it so that it uses the new settings.', 'Hot-Costing',
mtInformation, [mbOK], 0);
Application.Terminate;
end
else
begin
etc...
MsgDlg is a custom version from an article in Delphi Informant yonks ago - replace it with
whatever you want.
Hope that helps
... Joe
Member of the UK Borland User Group |
|
| Back to top |
|
 |
Glenn Greatwood Guest
|
Posted: Mon Feb 05, 2007 7:01 pm Post subject: Re: check for LocalShare=True |
|
|
Many thanks chaps
Regards
Glenn
"Joe Griffin" <JoeGriffin (AT) nospam (DOT) cix.co.uk> wrote in message
news:VA.000000fa.00ac27c7 (AT) nospam (DOT) cix.co.uk...
| Quote: | Glenn Greatwood wrote:
Is it possible for my app to check that Local Share is set to true on
start-up? If so..how...
As I just posted in b.p.bde
From production code ...
function TMainForm.CheckLocalShare: Boolean;
var
ASYSConfig : SYSConfig;
Reg : TRegistry;
begin
{ Ensure BDE is initialised }
Session.Open;
Reg := TRegistry.Create; // Defaults to HKEY_CURRENT_USER
try
if NOT Reg.OpenKey('Software\Borland\Delphi', False) then
begin
if (DbiGetSysConfig(ASYSConfig) = DbiErr_None) and
not ASYSConfig.bLocalShare then
begin
result := False;
end
else
begin
result := True;
end;
end
else
begin
// Development machine - don't set Local Share
result := True;
end;
finally // wrap up
Reg.CloseKey;
Reg.Free;
end; // try/finally
end;
procedure TMainForm.SetConfigParameter(Param: string; Value: string);
var
hCur: hDBICur;
rslt: DBIResult;
Config: CFGDesc;
Path, Option: string;
Found: boolean;
Temp: array[0..255] of char;
begin
hCur := nil;
Found := False;
Check(DbiInit(nil)); // initialise the BDE
try
if Pos(';', Param) = 0 then
raise EDatabaseError.Create('Invalid parameter passed to function.
There must ' +
'be a semi-colon delimited sting passed');
Path := Copy(Param, 0, Pos(';', Param) - 1);
Option := Copy(Param, Pos(';', Param) + 1, Length(Param) - Pos(';',
Param));
Check(DbiOpenCfgInfoList(nil, dbiREADWRITE, cfgPERSISTENT,
StrPCopy(Temp, Path), hCur));
repeat
rslt := DbiGetNextRecord(hCur, dbiNOLOCK, @Config, nil);
if rslt = DBIERR_NONE then
begin
if StrPas(Config.szNodeName) = Option then
begin
StrPCopy(Config.szValue, Value);
Check(DbiModifyRecord(hCur, @Config, FALSE));
Found := True;
break;
end;
end
else if rslt <> DBIERR_EOF then
Check(rslt);
until rslt <> DBIERR_NONE;
if Found = False then
raise EDatabaseError.Create(Param + ' entry was not found in
configuration file');
finally
if hCur <> nil then
Check(DbiCloseCursor(hCur));
Check(DbiExit); // Ensure the changes are saved
end;
end;
Called by:
procedure TMainForm.FormShow(Sender: TObject);
begin
if NOT CheckLocalShare then
begin
// Local Share was not set, so set it and restart
SetConfigParameter('\SYSTEM\INIT\;LOCAL SHARE', 'TRUE');
MsgDlg('In order to improve the robustness of Hot-costing,' + #13 +
'there has been a change to a System setting on your machine.'
+ #13#13 +
'This program will now close!' + #13#13 +
'Please restart it so that it uses the new settings.',
'Hot-Costing',
mtInformation, [mbOK], 0);
Application.Terminate;
end
else
begin
etc...
MsgDlg is a custom version from an article in Delphi Informant yonks ago -
replace it with
whatever you want.
Hope that helps
... Joe
Member of the UK Borland User Group
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|