home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap08 / howto04 / delphi10 / drivecap / capform.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-13  |  4.1 KB  |  160 lines

  1. unit Capform;
  2.  
  3. interface
  4.  
  5. uses
  6. {$IFDEF WIN32}
  7.   Bde,
  8. {$ELSE}
  9.   DbiErrs,
  10. {$ENDIF}
  11.   Infotabs,
  12.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics,
  13.   Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables;
  14.  
  15. type
  16.  
  17.   TDriverCapabilityForm = class(TForm)
  18.     DriverDataSource: TDataSource;
  19.     DriverDBGrid: TDBGrid;
  20.     FieldTypeDBGrid: TDBGrid;
  21.     FieldTypeDataSource: TDataSource;
  22.     TableTypeDataSource: TDataSource;
  23.     IndexTypeDBGrid: TDBGrid;
  24.     DriversLabel: TLabel;
  25.     FieldTypesLabel: TLabel;
  26.     IndexTypesLabel: TLabel;
  27.     TableTypeDBGrid: TDBGrid;
  28.     TableTypesLabel: TLabel;
  29.     IndexTypeDataSource: TDataSource;
  30.     procedure FormCreate(Sender: TObject);
  31.     procedure DriverDataSourceDataChange(Sender: TObject;
  32.       Field: TField);
  33.   private
  34.     { Private declarations }
  35.     DriverListTable: TDriverListTable;
  36.     TableTypesListTable: TTableTypesListTable;
  37.     FieldTypesListTable: TFieldTypesListTable;
  38.     IndexTypesListTable: TIndexTypesListTable;
  39.   public
  40.     { Public declarations }
  41.   end;
  42.  
  43.  
  44. var
  45.   DriverCapabilityForm: TDriverCapabilityForm;
  46.  
  47. implementation
  48.  
  49. {$R *.DFM}
  50.  
  51.  
  52. procedure TDriverCapabilityForm.FormCreate(Sender: TObject);
  53. begin
  54.  
  55.   DriverListTable := TDriverListTable.Create( Self );
  56.   DriverDataSource.DataSet := DriverListTable;
  57.   DriverDataSource.DataSet.Open;
  58.  
  59. end;
  60.  
  61. procedure TDriverCapabilityForm.DriverDataSourceDataChange(
  62.   Sender: TObject; Field: TField);
  63. begin
  64.  
  65.   if DriverDataSource.DataSet <> Nil then
  66.   begin
  67.  
  68.     with DriverDataSource.DataSet do
  69.     begin
  70.  
  71.       try
  72.  
  73.         { First close and free any existing in-memory tables. }
  74.  
  75.         if TableTypeDataSource.DataSet <> Nil then
  76.         begin
  77.           TableTypeDataSource.DataSet.Close;
  78.           TableTypeDataSource.DataSet.Free;
  79.           TableTypeDataSource.DataSet := Nil;
  80.         end;
  81.  
  82.         if FieldTypeDataSource.DataSet <> Nil then
  83.         begin
  84.           FieldTypeDataSource.DataSet.Close;
  85.           FieldTypeDataSource.DataSet.Free;
  86.           FieldTypeDataSource.DataSet := Nil;
  87.         end;
  88.  
  89.         if IndexTypeDataSource.DataSet <> Nil then
  90.         begin
  91.           IndexTypeDataSource.DataSet.Close;
  92.           IndexTypeDataSource.DataSet.Free;
  93.           IndexTypeDataSource.DataSet := Nil;
  94.         end;
  95.  
  96.         { Then reopen them. }
  97.  
  98.         TableTypesListTable := TTableTypesListTable.Create(
  99.           FieldByName( 'DRIVERNAME' ).AsString,
  100.           Self
  101.         );
  102.         TableTypeDataSource.DataSet := TableTypesListTable;
  103.         TableTypeDataSource.DataSet.Open;
  104.  
  105.         FieldTypesListTable := TFieldTypesListTable.Create(
  106.           FieldByName( 'DRIVERNAME' ).AsString,
  107.           Self
  108.         );
  109.         FieldTypeDataSource.DataSet := FieldTypesListTable;
  110.         FieldTypeDataSource.DataSet.Open;
  111.  
  112.         IndexTypesListTable := TIndexTypesListTable.Create(
  113.           FieldByName( 'DRIVERNAME' ).AsString,
  114.           Self
  115.         );
  116.         IndexTypeDataSource.DataSet := IndexTypesListTable;
  117.         IndexTypeDataSource.DataSet.Open;
  118.  
  119.       except
  120.  
  121.         on E: EDBEngineError do
  122.         begin
  123.           { You know what driver is creating problems...}
  124.           with EDBEngineError(E).Errors[
  125.             Pred(EDBEngineError(E).ErrorCount)] do
  126.  
  127.           begin
  128.  
  129.             { ...so give the user a more meaningful message.}
  130.             if ErrorCode = DBIERR_CANTLOADLIBRARY then
  131.             begin
  132.               E.Message := 'Missing ' +
  133.                 FieldByName( 'DRIVERNAME' ).AsString +
  134.                 ' driver DLL';
  135.             end
  136.  
  137.             else if ErrorCode = DBIERR_DRIVERNOTLOADED then
  138.             begin
  139.               E.Message := FieldByName( 'DRIVERNAME' ).AsString +
  140.                 ' driver not loaded';
  141.             end; { if }
  142.  
  143.           end; { with EDBEngineError(E)... }
  144.  
  145.           { Re-reaise whatever DBEngineError was detected. }
  146.  
  147.           raise;
  148.  
  149.         end; { on EDBEngineError }
  150.  
  151.       end; { try ... except }
  152.  
  153.     end; { with DriverDataSource.DataSet }
  154.  
  155.   end; { if DriverDataSource.DataSet <> Nil }
  156.  
  157. end;
  158.  
  159. end.
  160.