Board index » delphi » check for LocalShare=True
Glenn Greatwood
![]() Delphi Developer |
Glenn Greatwood
![]() Delphi Developer |
check for LocalShare=True2007-02-01 06:03:20 PM delphi126 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 |
Bill Todd
![]() Delphi Developer |
2007-02-01 10:16:03 PM
Re:check for LocalShare=True
Glenn Greatwood writes:
QuoteHi -- Bill Todd (TeamB) |
Joe Griffin
![]() Delphi Developer |
2007-02-02 05:13:53 AM
Re:check for LocalShare=True
Glenn Greatwood writes:
QuoteIs it possible for my app to check that Local Share is set to true on 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 |
Glenn Greatwood
![]() Delphi Developer |
2007-02-05 09:01:16 PM
Re:check for LocalShare=True
Many thanks chaps
Regards Glenn "Joe Griffin" <XXXX@XXXXX.COM>writes QuoteGlenn Greatwood writes: |