home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / full / delphi / RUNIMAGE / DELPHI30 / SOURCE / VCL / DRTABLE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-03  |  4.2 KB  |  199 lines

  1. unit DRTable;
  2.  
  3. interface
  4.  
  5. uses Windows, SysUtils, Classes, BDE, DB, DBTables;
  6.  
  7. type
  8.  
  9. { TDRList }
  10.  
  11.   TDRList = class(TBdeDataSet)
  12.   protected
  13.     function CreateHandle: HDBICur; override;
  14.   end;
  15.  
  16. { TDRDataSet }
  17.  
  18.   TDRDataSet = class(TBdeDataSet)
  19.   private
  20.     FDBIDR: HDBIDR;
  21.   public
  22.     property DRHandle: HDBIDR read FDBIDR write FDBIDR;
  23.   end;
  24.  
  25. { TDRObjectDescList }
  26.  
  27.   TDRObjectDescList = class(TDRDataSet)
  28.   protected
  29.     function CreateHandle: HDBICur; override;
  30.   end;
  31.  
  32. { TDRObjectItems }
  33.  
  34.   TDRObjectItems = class(TDRDataset)
  35.   protected
  36.     FObjectName: string;
  37.   end;
  38.  
  39. { TDRRelationshipDescList }
  40.  
  41.   TDRRelationshipDescList = class(TDRObjectItems)
  42.   protected
  43.     function CreateHandle: HDBICur; override;
  44.   published
  45.     property ObjectTypeName: string read FObjectName write FObjectName;
  46.   end;
  47.  
  48. { TDRAttrDescList }
  49.  
  50.   TDRAttrDescList = class(TDRObjectItems)
  51.   protected
  52.     function CreateHandle: HDBICur; override;
  53.   published
  54.     property TypeName: string read FObjectName write FObjectName;
  55.   end;
  56.  
  57. { TDRInstanceItems }
  58.  
  59.   TDRInstanceItems = class (TDRObjectItems)
  60.   private
  61.     FCond: string;
  62.   published
  63.     property Condition: string read FCond write FCond;
  64.   end;
  65.  
  66. { TDRObjectList }
  67.  
  68.   TDRObjectList = class(TDRInstanceItems)
  69.   private
  70.     FRelName: string;
  71.     FSource: DRObject;
  72.   protected
  73.     function CreateHandle: HDBICur; override;
  74.   public
  75.     procedure NavigateFrom(const ASource: DRObject; const ARelationship: string);
  76.   published
  77.     property ObjectTypeName: string read FObjectName write FObjectName;
  78.   end;
  79.  
  80. { TDRRelationshipList }
  81.  
  82.   TDRRelationshipList = class(TDRInstanceItems)
  83.   private
  84.     FSource, FTarget: DRObject;
  85.   protected
  86.     function CreateHandle: HDBICur; override;
  87.   public
  88.     procedure NavigateFromTo(const ASource, ATarget: DRObject);
  89.   published
  90.     property RelationshipTypeName: string read FObjectName write FObjectName;
  91.   end;
  92.  
  93. { TQueryDescription }
  94.  
  95.   TQueryDescription = class(TBdeDataset)
  96.   private
  97.     FQuery: TQuery;
  98.     FPrepared: Boolean;
  99.   protected
  100.     function CreateHandle: HDBICur; override;
  101.     procedure DestroyHandle; override;
  102.   public
  103.     property Query: TQuery read FQuery write FQuery;
  104.   end;
  105.  
  106. const
  107.   NullDRObject: DRObject = (ulObjId: 0; iVersion: 0);
  108.  
  109. { **************************************************************************** }
  110.  
  111. implementation
  112.  
  113. { TDRList }
  114.  
  115. function TDRList.CreateHandle: HDBICur;
  116. begin
  117.   Check(DbiOpenRepositoryList(Result));
  118. end;
  119.  
  120. { TDRObjectDescList }
  121.  
  122. function TDRObjectDescList.CreateHandle: HDBICur;
  123. begin
  124.   Check(DbiDROpenObjectTypeList(DRHandle, Result));
  125. end;
  126.  
  127. { TDRRelationshipDescList }
  128.  
  129. function TDRRelationshipDescList.CreateHandle: HDBICur;
  130. begin
  131.   Check(DbiDROpenRelTypeList(DRHandle, PChar(ObjectTypeName), Result));
  132. end;
  133.  
  134. { TDRAttrDescList }
  135.  
  136. function TDRAttrDescList.CreateHandle: HDBICur;
  137. begin
  138.   Check(DbiDROpenAttrTypeList(DRHandle, PChar(TypeName), Result));
  139. end;
  140.  
  141. { TDRObjectList }
  142.  
  143. function TDRObjectList.CreateHandle: HDBICur;
  144. begin
  145.   Check(DbiDROpenObjSet(DRHandle, PChar(ObjectTypeName), @FSource, Pointer(FRelName),
  146.     Pointer(Condition), Result));
  147. end;
  148.  
  149. procedure TDRObjectList.NavigateFrom(const ASource: DRObject; const
  150.   ARelationship: string);
  151. begin
  152.   FSource := ASource;
  153.   FRelName := ARelationship;
  154. end;
  155.  
  156. { TDRRelationshipList }
  157.  
  158. function TDRRelationshipList.CreateHandle: HDBICur;
  159. var
  160.   PS, PT: pDRObject;
  161. begin
  162.   if FSource.ulObjId = 0 then PS := nil
  163.   else PS := @FSource;
  164.   if FTarget.ulObjId = 0 then PT := nil
  165.   else PT := @FTarget;
  166.   Check(DbiDROpenRelSet(DRHandle, PChar(RelationshipTypeName), PS, PT,
  167.     Pointer(Condition), Result));
  168. end;
  169.  
  170. procedure TDRRelationshipList.NavigateFromTo(const ASource, ATarget: DRObject);
  171. begin
  172.   FSource := ASource;
  173.   FTarget := ATarget;
  174. end;
  175.  
  176. { TQueryDescription }
  177.  
  178. function TQueryDescription.CreateHandle: HDBICur;
  179. begin
  180.   Result := nil;
  181.   if Assigned(Query) then
  182.   begin
  183.     if Query.StmtHandle = nil then
  184.     begin
  185.       Query.Prepare;
  186.       FPrepared := True;
  187.     end;
  188.     Check(DBIQGetBaseDescs(Query.StmtHandle, Result));
  189.   end;
  190. end;
  191.  
  192. procedure TQueryDescription.DestroyHandle;
  193. begin
  194.   inherited DestroyHandle;
  195.   if FPrepared then Query.UnPrepare;
  196. end;
  197.  
  198. end.
  199.