unit SetBDE;
   { ----- Проверка и корректировка настроек BDE ---- }
   { Paradox: DBWINUS0;   DBase: DBWINUS0 or db866ru0 }
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls;

type
  TSetBDEFrm = class(TForm)
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    CheckBox1: TCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    StaticText1: TStaticText;
    Label3: TLabel;
    StaticText2: TStaticText;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    Panel1: TPanel;
    Label5: TLabel;
    Bevel1: TBevel;
    ComboBox1: TComboBox;
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
  private
    procedure NewBDELangDriver(var LangDrvDBase, LangDrvParadox: string;
                var DBaseLevel:byte);
  end;

var
  SetBDEFrm: TSetBDEFrm;

 // главная вызываемая процедура
procedure ControlBDELangDriver(var LangDrvDBase, LangDrvParadox: string;
          var DBaseLevel: byte);

implementation

{$R *.dfm}

uses Registry;

procedure TSetBDEFrm.CheckBox2Click(Sender: TObject);
begin
  if CheckBox2.Checked then
     CheckBox3.Checked:= false;
  ComboBox1.Enabled:= false;
  ComboBox1.Color:= clBtnFace;
end;

procedure TSetBDEFrm.CheckBox3Click(Sender: TObject);
begin
  if CheckBox3.Checked then
     CheckBox2.Checked:= false;
  ComboBox1.Enabled:= CheckBox3.Checked;
  if ComboBox1.Enabled then ComboBox1.Color:= clWindow
  else ComboBox1.Color:= clBtnFace;
end;

   { --- Определение кодовых страниц в BDE --- }

procedure BDELangDriver(var LangDrvDBase, LangDrvParadox: string;
                        var DBaseLevel: byte);
var
  Registry: TRegistry;
begin
  Registry:= TRegistry.Create;   // создаём объект TRegistry
  Registry.RootKey := HKey_Local_Machine;  // устанавливаем корневой ключ
  LangDrvDBase:= '';
  LangDrvParadox:= '';
  DBaseLevel:= 0;
     // открываем ключ
  if Registry.OpenKey('Software\Borland\DataBase Engine\Settings\Drivers\DBase\Init',false) then
  begin
     // читаем значение параметра
    LangDrvDBase:= Registry.ReadString('LangDriver');
    Registry.CloseKey; // закрываем и освобождаем ключ
    if Registry.OpenKey('Software\Borland\DataBase Engine\Settings\Drivers\DBase\Table Create',false) then
      DBaseLevel:= StrToInt(Registry.ReadString('Level'));
  end
  else
    Application.MessageBox('Возможно, не установлен драйвер BDE (Borland Database Engine)',
      ' Критическая ошибка', MB_ICONSTOP);
  Registry.CloseKey;

  if Registry.OpenKey('Software\Borland\DataBase Engine\Settings\Drivers\Paradox\Init',false) then
    LangDrvParadox:= Registry.ReadString('LangDriver')
  else if LangDrvDBase <> '' then
    Application.MessageBox('Возможно, неправильно установлен драйвер BDE (Borland Database Engine)',
        ' Критическая ошибка', MB_ICONSTOP);
  Registry.CloseKey;
  Registry.Free;
  LangDrvParadox:= AnsiUpperCase(LangDrvParadox);
  LangDrvDBase:= AnsiUpperCase(LangDrvDBase)
end;

     { --- Переопределение кодовых страниц в BDE --- }

procedure TSetBDEFrm.NewBDELangDriver(var LangDrvDBase, LangDrvParadox: string;
          var DBaseLevel:byte);
const
  Level: array[0..3] of byte = (7,5,4,3);
var
  Registry: TRegistry; L:integer;
begin
  Registry := TRegistry.Create;
  Registry.RootKey := HKey_Local_Machine;
     // Paradox
  if CheckBox1.Checked and (LangDrvParadox <> 'DBWINUS0') then
    if Registry.OpenKey('Software\Borland\DataBase Engine\Settings\Drivers\Paradox\Init',false) then
    begin
      LangDrvParadox:= 'DBWINUS0';
      Registry.WriteString('LangDriver', LangDrvParadox);
      Registry.CloseKey;
    end;
     // DBase - DBWINUS0
  if CheckBox2.Checked and (LangDrvDBase <> 'DBWINUS0') then begin
    if Registry.OpenKey('Software\Borland\DataBase Engine\Settings\Drivers\DBase\Init',false) then
    begin
      LangDrvDBase:= 'DBWINUS0';
      Registry.WriteString('LangDriver', LangDrvDBase);
      Registry.CloseKey;
    end;
    if DBaseLevel <> 7 then
      if Registry.OpenKey('Software\Borland\DataBase Engine\Settings\Drivers\DBase\Table Create',false) then
      begin
        DBaseLevel:= 7;
        Registry.WriteString('Level', '7');
        Registry.CloseKey;
      end
  end
  else if CheckBox3.Checked then begin  // DBase - db866ru0
    if (LangDrvDBase <> 'DB866RU0') then
      if Registry.OpenKey('Software\Borland\DataBase Engine\Settings\Drivers\DBase\Init',false) then
      begin
        LangDrvDBase:= 'DB866RU0';
        Registry.WriteString('LangDriver','db866ru0');
        Registry.CloseKey;
      end;
    L:= ComboBox1.ItemIndex;
    if L in [0..3] then L:= Level[L] else L:=7;
    if L <> DBaseLevel then
      if Registry.OpenKey('Software\Borland\DataBase Engine\Settings\Drivers\DBase\Table Create',false) then
      begin
        DBaseLevel:= L;
        Registry.WriteString('Level', IntToStr(L));
        Registry.CloseKey;
      end
  end;
  Registry.Free;
end;

   { ---- Проверка и корректировка настроек BDE ---- }
        // главная процедура - вызывается извне

procedure ControlBDELangDriver(var LangDrvDBase, LangDrvParadox: string;
          var DBaseLevel: byte);
const Level : array[0..3] of byte = (7,5,4,3);
var s: string; L:integer;
begin
     //  Проверка настроек BDE
  BDELangDriver(LangDrvDBase, LangDrvParadox, DBaseLevel);  // текущие настройки
  if (LangDrvDBase = '') or (LangDrvParadox = '') then exit;  // замечание уже было
  if not ((LangDrvParadox = 'DBWINUS0') and
    (((LangDrvDBase = 'DB866RU0') and (DBaseLevel > 3)) or
      (LangDrvDBase = 'DBWINUS0'))) then
  begin
    // изменение настроек BDE
    SetBDEFrm:= TSetBDEFrm.Create(nil);
    with SetBDEFrm do begin
      if (LangDrvParadox = 'DBWINUS0') and
         (LangDrvDBase = 'DB866RU0') and (DBaseLevel = 3) then
      Label5.Caption:= 'Настройки в DBase неудобные - '#13#10 +
        'рекомендуется установить следующие:';
      StaticText1.Caption:= ' ' + LangDrvParadox;
      s:= LangDrvDBase;
      if s <> 'DBWINUS0' then s:= s + ', ver.' + IntToStr(DBaseLevel);
      StaticText2.Caption:= ' ' + s;
      L:=0;
      case DBaseLevel of
        5: L:=1;
        4: L:=2;
      end;
      ComboBox1.ItemIndex:= L;
      if LangDrvDBase = 'DBWINUS0' then begin
        CheckBox2.Checked:= true;
        CheckBox3.Checked:= false;
      end
      else begin
        CheckBox3.Checked:= true;
        CheckBox2.Checked:= false
      end;
      if ShowModal = 1 then
        NewBDELangDriver(LangDrvDBase, LangDrvParadox, DBaseLevel);
      Free
    end { with SetBDEFrm }
  end
end;

end.
Hosted by uCoz