Board index » delphi » How to set LOCAL_SHARE?

How to set LOCAL_SHARE?

Hi all,
Does anybody know how to set famous "LOCAL SHARE" to TRUE programmatically?

Thanks a lot in advance.
Sergei Soudakov

 

Re:How to set LOCAL_SHARE?


hey Sergei,

I wrote a little programm a while ago (Delphi 1, BDE 2.5) that does that.
It is not that short, so send me an e-mail and tell me if that is what
you need. I will then mail it to u.

cu
HANZ

becons...@aol.com

Sergei Soudakov <b...@uniqum.tomsk.su> schrieb im Beitrag
<01bd1e8b$8aab2000$1fb97...@DIMAPC.tomsk.su>...

Quote
> Hi all,
> Does anybody know how to set famous "LOCAL SHARE" to TRUE
programmatically?

> Thanks a lot in advance.
> Sergei Soudakov

Re:How to set LOCAL_SHARE?


Quote
>Hi all,
>Does anybody know how to set famous "LOCAL SHARE" to TRUE programmatically?

>Thanks a lot in advance.
>Sergei Soudakov

Open the BDE Manager and then, select the "Configuration" tab, and then the
System\INIT option: you'll see the LOCAL SHARE editline there.

Saludos,

    Pedro Agull

Re:How to set LOCAL_SHARE?


Quote
>Does anybody know how to set famous "LOCAL SHARE" to TRUE programmatically?

There are several ways to do this.   Assuming you are using 32bit bde
it is a registry setting you can modify.

You can also use BDE code to affect the change.

And with 32bit delphi the TSession component has a protected method
"ModifyConfigParams" that you can surface in a descendant of Tsession.

Since you didn't specify what version you are trying to accomplish
this in BDE code is the most universal.  This unit can help you out
there

............
unit CFGTOOL;

interface

uses SysUtils, Classes, DB, DbiProcs, DbiTypes, DbiErrs;

type
  TBDEConfig = class(TComponent)
    private
        FLocalShare : Boolean;
        FMinBufSize : Integer;
        FMaxBufSize : Integer;
        FSystemLangDriver : String;
        FParadoxLangDriver : String;
        FMaxFileHandles : Integer;
        FNetFileDir : String;
        FTableLevel : String;
        FBlockSize : Integer;
        FDefaultDriver : String;
        FStrictIntegrity : Boolean;
        FAutoODBC : Boolean;

        procedure Init;
        procedure SetLocalShare(Value : Boolean);
        procedure SetMinBufSize(Value : Integer);
        procedure SetMaxBufSize(Value : Integer);
        procedure SetSystemLangDriver(Value : String);
        procedure SetParadoxLangDriver(Value : String);
        procedure SetMaxFileHandles(Value : Integer);
        procedure SetNetFileDir(Value : String);
        procedure SetTableLevel(Value : String);
        procedure SetBlockSize(Value : Integer);
        procedure SetDefaultDriver(Value : String);
        procedure SetAutoODBC(Value : Boolean);
        procedure SetStrictIntegrity(Value : Boolean);
        procedure UpdateCFGFile( path, item, value : string);

    protected

    public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
    published
        property LocalShare : Boolean read FLocalShare write
SetLocalShare;
        property MinBufSize : Integer read FMinBufSize write
SetMinBufSize;
        property MaxBufSize : Integer read FMaxBufSize write
SetMaxBufSize;
        property SystemLangDriver : String
             read FSystemLangDriver write SetSystemLangDriver;
        property ParadoxLangDriver : String
             read FParadoxLangDriver write SetParadoxLangDriver;
        property MaxFileHandles : Integer
             read FMaxFileHandles write SetMaxFileHandles;
        property NetFileDir : String read FNetFileDir write
SetNetFileDir;
        property TableLevel : String
             read FTableLevel write SetTableLevel;
        property BlockSize : Integer
             read FBlockSize write SetBlockSize;
        property DefaultDriver : string
             read FDefaultDriver write SetDefaultDriver;
        property AutoODBC : Boolean
             read FAutoODBC write SetAutoODBC;
        property StrictIntegrity : Boolean
             read FStrictIntegrity write SetStrictIntegrity;

  end;

procedure Register;

implementation

function StrToBoolean( Value : string) : Boolean; begin
  if (UpperCase(Value) = 'TRUE') or
     (UpperCase(Value) = 'ON') or
     (UpperCase(Value) = 'YES') or
     (UpperCase(Value) = '.T.' ) then
     Result := True
  else
     Result := False; end;

function BooleanToStr( Value : Boolean) : String; begin
  if Value then
     Result := 'TRUE'
  else
     Result := 'FALSE'; end;

procedure Register; begin
     RegisterComponents('Data Access', [TBDEConfig]); end;

procedure TBDEConfig.Init; var
  h: hDBICur;
  pCfgDes: pCFGDesc;
  n, v : string; begin Check(DbiOpenCfgInfoList(nil, dbiREADWRITE,
cfgPersistent,'\SYSTEM\INIT', h)); GetMem(pCfgDes, sizeof(CFGDesc));
try
  FillChar(pCfgDes^, sizeof(CFGDesc), #0);
  while (DbiGetNextRecord(h, dbiWRITELOCK, pCfgDes, nil) =
DBIERR_NONE) do begin
     n := StrPas(pCfgDes^.szNodeName);
     v := StrPas(pCfgDes^.szValue);
     if n = 'LOCAL SHARE' then
        FLocalShare := StrToBoolean(v)
     else if n = 'MINBUFSIZE' then
        FMinBufSize := StrToInt(v)
     else if n = 'MAXBUFSIZE' then
        FMaxBufSize := StrToInt(v)
     else if n = 'MAXFILEHANDLES' then
        FMaxFileHandles := StrToInt(v)
     else if n = 'LANGDRIVER' then
        FSystemLangDriver := v
     else if n = 'AUTO ODBC' then
        FAutoODBC := StrToBoolean(v)
     else if n = 'DEFAULT DRIVER' then
        FDefaultDriver := v;
  end;
  if (h <> nil) then DbiCloseCursor(h);
  Check(DbiOpenCfgInfoList(nil, dbiREADWRITE,
cfgPersistent,'\DRIVERS\PARADOX\INIT', h));
  FillChar(pCfgDes^, sizeof(CFGDesc), #0);
  while (DbiGetNextRecord(h, dbiWRITELOCK, pCfgDes, nil) =
DBIERR_NONE) do begin
     n := StrPas(pCfgDes^.szNodeName);
     v := StrPas(pCfgDes^.szValue);
     if n = 'NET DIR' then
        FNetFileDir := v
     else if n = 'LANGDRIVER' then
        FParadoxLangDriver := v;
  end;
  if (h <> nil) then DbiCloseCursor(h);
  Check(DbiOpenCfgInfoList(nil, dbiREADWRITE,
cfgPersistent,'\DRIVERS\PARADOX\TABLE CREATE', h));
  FillChar(pCfgDes^, sizeof(CFGDesc), #0);
  while (DbiGetNextRecord(h, dbiWRITELOCK, pCfgDes, nil) =
DBIERR_NONE) do begin
     n := StrPas(pCfgDes^.szNodeName);
     v := StrPas(pCfgDes^.szValue);
     if n = 'LEVEL' then
        FTableLevel := v
     else if n = 'BLOCK SIZE' then
        FBlockSize := StrToInt(v)
     else if n = 'STRICTINTEGRITY' then
        FStrictIntegrity := StrToBoolean(v);
  end; finally
  FreeMem(pCfgDes, sizeof(CFGDesc));
  if (h <> nil) then DbiCloseCursor(h); end; end;

procedure TBDEConfig.SetLocalShare(Value : Boolean); begin
  UpdateCfgFile('\SYSTEM\INIT','LOCAL SHARE',BooleanToStr(Value));
  FLocalShare := Value; end;

procedure TBDEConfig.SetMinBufSize(Value : Integer); begin
  UpdateCfgFile('\SYSTEM\INIT','MINBUFSIZE',IntToStr(Value));
  FMinBufSize := Value; end;

procedure TBDEConfig.SetMaxBufSize(Value : Integer); begin
  UpdateCfgFile('\SYSTEM\INIT','MAXBUFSIZE',IntToStr(Value));
  FMaxBufSize := Value; end;

procedure TBDEConfig.SetSystemLangDriver(Value : String); begin
  UpdateCfgFile('\SYSTEM\INIT','LANGDRIVER',Value);
  FSystemLangDriver := Value; end;

procedure TBDEConfig.SetParadoxLangDriver(Value : String); begin
  UpdateCfgFile('\DRIVERS\PARADOX\INIT','LANGDRIVER',Value);
  FParadoxLangDriver := Value; end;

procedure TBDEConfig.SetMaxFileHandles(Value : Integer); begin
  UpdateCfgFile('\SYSTEM\INIT','MAXFILEHANDLES',IntToStr(Value));
  FMaxFileHandles := Value; end;

procedure TBDEConfig.SetNetFileDir(Value : String); begin
  UpdateCfgFile('\DRIVERS\PARADOX\INIT','NET DIR',Value);
  FNetFileDir := Value; end;

procedure TBDEConfig.SetTableLevel(Value : String); begin
  UpdateCfgFile('\DRIVERS\PARADOX\TABLE CREATE','LEVEL',Value);
  FTableLevel := Value; end;

procedure TBDEConfig.SetBlockSize(Value : Integer); begin
  UpdateCfgFile('\DRIVERS\PARADOX\TABLE CREATE','BLOCK
SIZE',IntToStr(Value));
  FBlockSize := Value; end;

procedure TBDEConfig.SetStrictIntegrity(Value : Boolean); begin
  UpdateCfgFile('\DRIVERS\PARADOX\TABLE
CREATE','STRICTINTEGRITY',BooleanToStr(Value));
  FStrictIntegrity := Value; end;

procedure TBDEConfig.SetDefaultDriver(Value : String); begin
  UpdateCfgFile('\SYSTEM\INIT','DEFAULT DRIVER',Value);
  FDefaultDriver := Value; end;

procedure TBDEConfig.SetAutoODBC(Value : Boolean); begin
  UpdateCfgFile('\SYSTEM\INIT','AUTO ODBC',BooleanToStr(Value));
  FAutoODBC := Value; end;

procedure TBDEConfig.UpdateCFGFile; var
  h : hDbiCur;
  pCfgDes: pCFGDesc;
  pPath : array[0..127] of char; begin StrPCopy(pPath,Path);
Check(DbiOpenCfgInfoList(nil, dbiREADWRITE, cfgPersistent, pPath, h));
GetMem(pCfgDes, sizeof(CFGDesc)); try
  FillChar(pCfgDes^, sizeof(CFGDesc), #0);
  while (DbiGetNextRecord(h, dbiWRITELOCK, pCfgDes, nil) =
DBIERR_NONE) do begin
    if StrPas(pCfgDes^.szNodeName) = item then begin
       StrPCopy(pCfgDes^.szValue,value);
       Check(DbiModifyRecord(h,pCfgDes,True));
    end;
  end; finally
  FreeMem(pCfgDes, sizeof(CFGDesc));
  if (h <> nil) then DbiCloseCursor(h); end; end;

co*nstructor TBDEConfig.Create(AOwner: TComponent); begin
  inherited Create(AOwner);
  Init; end;

destructor TBDEConfig.Destroy; begin
  inherited Destroy; end;

end.On 11 Jan 1998 12:15:09 GMT, "Sergei Soudakov"

Quote
<b...@uniqum.tomsk.su> wrote:
>H

--
Brian Bushay (TeamB)
Bbus...@DataGuidance.com

Re:How to set LOCAL_SHARE?


Sergei

Quote
> Does anybody know how to set famous "LOCAL SHARE" to TRUE

programmatically?

This is what I use in Delphi 3.  You'll need to include the Registry unit
in your Uses list.  Then use the following code:

  with tRegistry.Create do
  begin
    try
      RootKey := HKEY_LOCAL_MACHINE ;
      if not OpenKey( 'SOFTWARE\Borland\Database
Engine\Settings\SYSTEM\INIT', false ) then
        raise Exception.CreateFmt( 'Error Opening Key: %s', [ 'BDE' ] ) ;
      WriteString( 'LOCAL SHARE', 'TRUE' ) ;
    finally
      Free ;
    end ; { try..finally }
  end ; { with tRegistry do }

This works for me, but use at your own risk.  Can anyone else verify that
this is acceptable and safe?

Mike

Re:How to set LOCAL_SHARE?


Sorry, NO. I said "programmatically".
--
Sergei Soudakov

Re:How to set LOCAL_SHARE?


Thank you.

Think your approach is right. The only disadvantage I see is that you need
reinitialize BDE after that, because I suppose BDE never knows what are you
doing with registri if it is already running. Nevertheless, it is not a big
problem.

Have nice BDE
Sergei Soudakov

Re:How to set LOCAL_SHARE?


I use D3. Also Brian Bushay(TeamB) suggest nice solution. Anyway, thanks a
lot for your attention to my little problem.
--
Sergei Soudakov

Re:How to set LOCAL_SHARE?


Thanks a lot. You save my time from a lot of stupid exploration of Registry
entries or other junk.

 Long live TeamB!
Sergei Soudakov

Re:How to set LOCAL_SHARE?


Quote
Sergei Soudakov wrote:

> Thank you.

> Think your approach is right. The only disadvantage I see is that you need
> reinitialize BDE after that, because I suppose BDE never knows what are you
> doing with registri if it is already running. Nevertheless, it is not a big
> problem.

> Have nice BDE
> Sergei Soudakov

Hello,
  The right way is to get the function off the following web page:
http://www.borland.com/devsupport/bde/bdeapiex/dbiopencfginfolist.html

This procedure will also update the .CFG file if necessary.

 Scott
--
BDE Support:
 http://www.borland.com/devsupport/bde
Delphi Support:
 http://www.borland.com/devsupport/delphi
Common Delphi and BDE Questions and Answers:
 http://www.borland.com/devsupport/delphi/qanda/delphi3qa.html

Other Threads