home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / WIN / Programa / PXREST.ZIP / MAIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-30  |  8.8 KB  |  337 lines

  1. {$A+,B-,C-,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q+,R+,S+,T-,U-,V+,W-,X+,Y-,Z1}
  2. {$MINSTACKSIZE $00004000}
  3. {$MAXSTACKSIZE $00100000}
  4. {$IMAGEBASE $00400000}
  5. {$APPTYPE GUI}
  6.  
  7. // User interface to the Restruct unit that contains all the procedures
  8. //   necessary to change Paradox table version, block size, and strict
  9. //   integrity constraints.  To use the procedures in your program, simply
  10. //   use the .PAS or .DCU file in your project.
  11.  
  12. // A detailed explanation of this program is in the Restruct.Pas file.
  13.  
  14. unit main;
  15.  
  16. interface
  17.  
  18. uses
  19.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  20.   DB, DBTables, StdCtrls, BDE, Menus, TblOpen, Priv, Restruct, ExtCtrls;
  21.  
  22. const
  23.   FFalse = 0; FTrue = 1;
  24.   V3 = 0; V4 = 1; V5 = 2; V7 = 3;
  25.   BS1024 = 0; BS2048 = 1; BS4096 = 2; BS16384 = 3; BS32768 = 4;
  26.  
  27. type
  28.   TMainForm = class(TForm)
  29.     RestTbl: TTable;
  30.     MainMenu1: TMainMenu;
  31.     File1: TMenuItem;
  32.     OpenTable1: TMenuItem;
  33.     CloseTable1: TMenuItem;
  34.     N1: TMenuItem;
  35.     Exit1: TMenuItem;
  36.     Options1: TMenuItem;
  37.     PrivateDirectory1: TMenuItem;
  38.     Restructure1: TMenuItem;
  39.     RefreshTableSettings1: TMenuItem;
  40.     N2: TMenuItem;
  41.     Panel1: TPanel;
  42.     Label3: TLabel;
  43.     GroupBox1: TGroupBox;
  44.     Label1: TLabel;
  45.     Label2: TLabel;
  46.     Label4: TLabel;
  47.     VLbl: TLabel;
  48.     BSLbl: TLabel;
  49.     SILbl: TLabel;
  50.     GroupBox2: TGroupBox;
  51.     Label5: TLabel;
  52.     Label6: TLabel;
  53.     Label8: TLabel;
  54.     SICombo: TComboBox;
  55.     VCombo: TComboBox;
  56.     BSCombo: TComboBox;
  57.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  58.     procedure FormShow(Sender: TObject);
  59.     procedure FormCreate(Sender: TObject);
  60.     procedure VComboChange(Sender: TObject);
  61.     procedure Exit1Click(Sender: TObject);
  62.     procedure CloseTable1Click(Sender: TObject);
  63.     procedure Restructure1Click(Sender: TObject);
  64.     procedure OpenTable1Click(Sender: TObject);
  65.     procedure EnableComboBoxes(Enable: boolean);
  66.     procedure RefreshTableSettings1Click(Sender: TObject);
  67.     procedure PrivateDirectory1Click(Sender: TObject);
  68.   private
  69.     { Private declarations }
  70.     CursorProps: CURProps;
  71.     V34Block, V57Block, V3SI, V4GreaterSI, Versions: TStringList;
  72.   public
  73.     { Public declarations }
  74.   end;
  75.  
  76. var
  77.   MainForm: TMainForm;
  78.  
  79. implementation
  80.  
  81. {$R *.DFM}
  82.  
  83. procedure TMainForm.EnableComboBoxes(Enable: boolean);
  84. var
  85.   B: Byte;
  86.  
  87. begin
  88.   for B := 0 to ComponentCount - 1 do
  89.     if Components[B] is TComboBox then
  90.     begin
  91.       TComboBox(Components[B]).Enabled := Enable;
  92.       if Enable = False then
  93.         TComboBox(Components[B]).ItemIndex := -1;
  94.     end;
  95. end;
  96.  
  97. procedure TMainForm.FormCreate(Sender: TObject);
  98. begin
  99.   V34Block := TStringList.Create;
  100.   V57Block := TStringList.Create;
  101.   V3SI := TStringList.Create;
  102.   V4GreaterSI := TStringList.Create;
  103.   Versions := TStringList.Create;  
  104.   with Versions do
  105.   begin
  106.     Add('3');
  107.     Add('4');
  108.     Add('5');
  109.     Add('7');
  110.   end;
  111.   with V34Block do
  112.   begin
  113.     Add('1024');
  114.     Add('2048');
  115.     Add('4096');
  116.   end;
  117.   with V57Block do
  118.   begin
  119.     Add('1024');
  120.     Add('2048');
  121.     Add('4096');
  122.     Add('16384');
  123.     Add('32768');
  124.   end;
  125.   with V3SI do
  126.     Add('FALSE');
  127.   with V4GreaterSI do
  128.   begin
  129.     Add('FALSE');
  130.     Add('TRUE');
  131.   end;
  132.   VLbl.Caption := '';
  133.   BSLbl.Caption := '';
  134.   SILbl.Caption := '';
  135. end;
  136.  
  137. procedure TMainForm.VComboChange(Sender: TObject);
  138. begin
  139.   if (VCombo.Text = '3') or (VCombo.Text = '4') then
  140.     BSCombo.Items.Assign(V34Block);
  141.   if (VCombo.Text = '5') or (VCombo.Text = '7') then
  142.     BSCombo.Items.Assign(V57Block);
  143.  
  144.   case StrToInt(BSLbl.Caption) of
  145.     1024: BSCombo.ItemIndex := BS1024;
  146.     2048: BSCombo.ItemIndex := BS2048;
  147.     4096: BSCombo.ItemIndex := BS4096;
  148.     16384: BSCombo.ItemIndex := BS16384;
  149.     32768: BSCombo.ItemIndex := BS32768;
  150.   end;
  151.   if BSCombo.Text = '' then
  152.     BSCombo.ItemIndex := BS2048;
  153.  
  154.  
  155.   if VCombo.Text = '3' then
  156.      SICombo.Items.Assign(V3SI)
  157.    else
  158.      SICombo.Items.Assign(V4GreaterSI);
  159.  
  160.   if (UpperCase(SILbl.Caption) = 'TRUE') and (VCombo.Text <> '3') then
  161.     SICombo.ItemIndex := FTrue
  162.   else
  163.     SICombo.ItemIndex := FFalse;
  164.  
  165. end;
  166.  
  167. procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  168. begin
  169.   RestTbl.Close;
  170.   V34Block.Free;
  171.   V57Block.Free;
  172.   V3SI.Free;
  173.   V4GreaterSI.Free;
  174.   Versions.Free;  
  175. end;
  176.  
  177. procedure TMainForm.FormShow(Sender: TObject);
  178. begin
  179.   VCombo.Text := '';
  180.   BSCombo.Text := '';
  181.   SICombo.Text := '';
  182.   Restructure1.Enabled := False;
  183.   RefreshTableSettings1.Enabled := False;  
  184. end;
  185.  
  186. procedure TMainForm.Exit1Click(Sender: TObject);
  187. begin
  188.   Close;
  189. end;
  190.  
  191. procedure TMainForm.CloseTable1Click(Sender: TObject);
  192. begin
  193.   RestTbl.Close;
  194.   Restructure1.Enabled := False;
  195.   RefreshTableSettings1.Enabled := False;
  196.   EnableComboBoxes(False);
  197.   VLbl.Caption := '';
  198.   BSLbl.Caption := '';
  199.   SILbl.Caption := '';
  200. end;
  201.  
  202. procedure TMainForm.Restructure1Click(Sender: TObject);
  203. begin
  204.   Screen.Cursor := crHourGlass;
  205.   try
  206.     if VLbl.Caption <> VCombo.Text then
  207.     begin
  208.       AlterVersion(RestTbl, StrToInt(VCombo.Text));
  209.       if UpperCase(SICombo.Text) = 'TRUE' then
  210.          AlterStrictIntegrity(RestTbl, True);
  211.     end;
  212.  
  213.     if BSLbl.Caption <> BSCombo.Text then
  214.     begin
  215.       AlterBlockSize(RestTbl, StrToInt(BSCombo.Text));
  216.       if UpperCase(SICombo.Text) = 'TRUE' then
  217.          AlterStrictIntegrity(RestTbl, True);
  218.     end;
  219.  
  220.     if UpperCase(SILbl.Caption) <> UpperCase(SICombo.Text) then
  221.       if UpperCase(SICombo.Text) = 'TRUE' then
  222.         AlterStrictIntegrity(RestTbl, True)
  223.       else
  224.         AlterStrictIntegrity(RestTbl, False);
  225.   finally
  226.     Screen.Cursor := crDefault;
  227.   end;
  228. end;
  229.  
  230. procedure TMainForm.OpenTable1Click(Sender: TObject);
  231. begin
  232.   RestTbl.Close;
  233.   if TableOpenDlg.ShowModal = mrOk then
  234.   begin
  235.     try
  236.       RestTbl.TableName := TableOpenDlg.FileLb.FileName;
  237.       RestTbl.Open;
  238.     except
  239.       on E:Exception do
  240.       begin
  241.         RefreshTableSettings1.Enabled := False;
  242.         Restructure1.Enabled := False;
  243.         ShowMessage(E.Message);
  244.         Exit;
  245.       end;
  246.     end;
  247.     Label3.Caption := 'Current Table: ' + LowerCase(TableOpenDlg.FileLb.FileName);    
  248.     Check(DbiGetCursorProps(RestTbl.Handle, CursorProps));
  249.     with CursorProps do
  250.     begin
  251.       if strcomp(szTableType, szParadox) = 0 then
  252.       begin
  253.         VLbl.Caption := IntToStr(iTblLevel);
  254.         BSLbl.Caption := IntToStr(iBlockSize * 1024);
  255.         if bStrictRefInt = True then
  256.           SILbl.Caption := 'True'
  257.         else
  258.           SILbl.Caption := 'False';
  259.         // Copy data over to "New table settings"
  260.         BSCombo.Text := BSLbl.Caption;
  261.         case iTblLevel of
  262.           3: VCombo.ItemIndex := V3;
  263.           4: VCombo.ItemIndex := V4;
  264.           5: VCombo.ItemIndex := V5;
  265.           7: VCombo.ItemIndex := V7;
  266.         end;
  267.         if bStrictRefInt = True then
  268.           SICombo.ItemIndex := FTrue
  269.         else
  270.           SICombo.ItemIndex := FFalse;
  271.         if (VCombo.Text = '3') or (VCombo.Text = '4') then
  272.            BSCombo.Items.Assign(V34Block);
  273.         if (VCombo.Text = '5') or (VCombo.Text = '7') then
  274.           BSCombo.Items.Assign(V57Block);
  275.  
  276.         case StrToInt(BSLbl.Caption) of
  277.           1024: BSCombo.ItemIndex := BS1024;
  278.           2048: BSCombo.ItemIndex := BS2048;
  279.           4096: BSCombo.ItemIndex := BS4096;
  280.           16384: BSCombo.ItemIndex := BS16384;
  281.           32768: BSCombo.ItemIndex := BS32768;
  282.         end;
  283.  
  284.         if VCombo.Text = '3' then
  285.           SICombo.Items.Assign(V3SI)
  286.         else
  287.           SICombo.Items.Assign(V4GreaterSI);
  288.  
  289.         if UpperCase(SILbl.Caption) = 'TRUE' then
  290.           SICombo.ItemIndex := FTrue
  291.         else
  292.           SICombo.ItemIndex := FFalse;
  293.         Restructure1.Enabled := True;
  294.         RefreshTableSettings1.Enabled := True;
  295.         EnableComboBoxes(True);
  296.       end
  297.       else
  298.       begin
  299.         VLbl.Caption := 'N/A';
  300.         BSLbl.Caption := 'N/A';
  301.         SILbl.Caption := 'N/A';
  302.         Restructure1.Enabled := False;
  303.         RefreshTableSettings1.Enabled := False;        
  304.         EnableComboBoxes(False);
  305.       end;
  306.     end;
  307.   end;
  308. end;
  309.  
  310.  
  311. procedure TMainForm.RefreshTableSettings1Click(Sender: TObject);
  312. begin
  313.   Check(DbiGetCursorProps(RestTbl.Handle, CursorProps));
  314.   with CursorProps do
  315.   begin
  316.     VLbl.Caption := IntToStr(iTblLevel);
  317.     BSLbl.Caption := IntToStr(iBlockSize * 1024);
  318.     if bStrictRefInt = True then
  319.       SILbl.Caption := 'True'
  320.     else
  321.       SILbl.Caption := 'False';
  322.   end;
  323. end;
  324.  
  325. procedure TMainForm.PrivateDirectory1Click(Sender: TObject);
  326. begin
  327.   if PrivateDirForm.ShowModal = mrOk then
  328.     session.PrivateDir := PrivateDirForm.PrivDirEd.Text;
  329. end;
  330.  
  331. initialization
  332.   Application.Title := 'Paradox Table Utility';
  333.   session.open;
  334. finalization
  335.   session.close;
  336. end.
  337.