home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 March / Chip_2002-03_cd1.bin / zkuste / delphi / kompon / d5 / ADO.ZIP / src / AdoParameter.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-12-23  |  5.2 KB  |  210 lines

  1. unit AdoParameter;
  2.  
  3. interface
  4.  
  5. {$I Ado25.inc}
  6.  
  7. uses
  8.   ActiveX, Classes, Graphics, OleServer, StdVCL,  Windows,
  9.   Ado21Int, AdoConnection;
  10.  
  11. type
  12.   TParameter = class(TOleServer)
  13.   private
  14.     FIntf:        IParameter;
  15.     function      GetParameter: IParameter;
  16.   protected
  17.     procedure InitServerData; override;
  18.     function  Get_Name: WideString;
  19.     procedure Set_Name(const pbstr: WideString);
  20.     function  Get_Value: OleVariant;
  21.     procedure Set_Value(pvar: OleVariant);
  22.     function  Get_Type_: DataTypeEnum;
  23.     procedure Set_Type_(psDataType: DataTypeEnum);
  24.     procedure Set_Direction(plParmDirection: ParameterDirectionEnum);
  25.     function  Get_Direction: ParameterDirectionEnum;
  26.     procedure Set_Precision(pbPrecision: Byte);
  27.     function  Get_Precision: Byte;
  28.     procedure Set_NumericScale(pbScale: Byte);
  29.     function  Get_NumericScale: Byte;
  30.     procedure Set_Size(pl: Integer);
  31.     function  Get_Size: Integer;
  32.     function  Get_Attributes: Integer;
  33.     procedure Set_Attributes(plParmAttribs: Integer);
  34.   public
  35.     constructor Create(AOwner: TComponent); override;
  36.     destructor  Destroy; override;
  37.     procedure Connect; override;
  38.     procedure ConnectTo(svrIntf: IParameter);
  39.     procedure Disconnect; override;
  40.     procedure AppendChunk(Val: OleVariant);
  41.     property  Parameter: IParameter read GetParameter;
  42.     property Value: OleVariant read Get_Value write Set_Value;
  43.   published
  44.     property Name: WideString read Get_Name write Set_Name;
  45.     property Type_: DataTypeEnum read Get_Type_ write Set_Type_;
  46.     property Direction: ParameterDirectionEnum read Get_Direction write Set_Direction;
  47.     property Precision: Byte read Get_Precision write Set_Precision;
  48.     property NumericScale: Byte read Get_NumericScale write Set_NumericScale;
  49.     property Size: Integer read Get_Size write Set_Size;
  50.     property Attributes: Integer read Get_Attributes write Set_Attributes;
  51.   end;
  52.  
  53. implementation 
  54.  
  55. uses ComObj;
  56.  
  57. procedure TParameter.InitServerData;
  58. const
  59.   CServerData: TServerData = (
  60.     ClassID:   '{0000050B-0000-0010-8000-00AA006D2EA4}';
  61.     IntfIID:   '{0000050C-0000-0010-8000-00AA006D2EA4}';
  62.     EventIID:  '';
  63.     LicenseKey: nil;
  64.     Version: 500);
  65. begin
  66.   ServerData := @CServerData;
  67. end;
  68.  
  69. procedure TParameter.Connect;
  70. var
  71.   punk: IUnknown;
  72. begin
  73.   if FIntf = nil then
  74.   begin
  75.     punk := GetServer;
  76.     Fintf:= punk as IParameter;
  77.   end;
  78. end;
  79.  
  80. procedure TParameter.ConnectTo(svrIntf: IParameter);
  81. begin
  82.   Disconnect;
  83.   FIntf := svrIntf;
  84. end;
  85.  
  86. procedure TParameter.DisConnect;
  87. begin
  88.   if Fintf <> nil then
  89.   begin
  90.     FIntf := nil;
  91.   end;
  92. end;
  93.  
  94. function TParameter.GetParameter: IParameter;
  95. begin
  96.   if FIntf = nil then
  97.     Connect;
  98.   Assert(FIntf <> nil, 'Parameter is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
  99.   Result := FIntf;
  100. end;
  101.  
  102. constructor TParameter.Create(AOwner: TComponent);
  103. begin
  104.   inherited Create(AOwner);
  105. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  106.   FProps := TParameterProperties.Create(Self);
  107. {$ENDIF}
  108. end;
  109.  
  110. destructor TParameter.Destroy;
  111. begin
  112.   inherited Destroy;
  113. end;
  114.  
  115. function  TParameter.Get_Name: WideString;
  116. begin
  117.   Result := Parameter.Name;
  118. end;
  119.  
  120. procedure TParameter.Set_Name(const pbstr: WideString);
  121.   { Warning: The property Name has a setter and a getter whose
  122.   types do not match. Delphi was unable to generate a property of
  123.   this sort and so is using a Variant to set the property instead. }
  124. var
  125.   InterfaceVariant: OleVariant;
  126. begin
  127.   InterfaceVariant := Parameter;
  128.   InterfaceVariant.Name := pbstr;
  129. end;
  130.  
  131. function  TParameter.Get_Value: OleVariant;
  132. var
  133.   InterfaceVariant : OleVariant;
  134. begin
  135.   InterfaceVariant := Parameter;
  136.   Result := InterfaceVariant.Value;
  137. end;
  138.  
  139. procedure TParameter.Set_Value(pvar: OleVariant);
  140. begin
  141.   Parameter.Value := pvar;
  142. end;
  143.  
  144. function  TParameter.Get_Type_: DataTypeEnum;
  145. begin
  146.   Result := Parameter.Type_;
  147. end;
  148.  
  149. procedure TParameter.Set_Type_(psDataType: DataTypeEnum);
  150. begin
  151.   Parameter.Set_Type_(psDataType);
  152. end;
  153.  
  154. procedure TParameter.Set_Direction(plParmDirection: ParameterDirectionEnum);
  155. begin
  156.   Parameter.Direction := plParmDirection;
  157. end;
  158.  
  159. function  TParameter.Get_Direction: ParameterDirectionEnum;
  160. begin
  161.   Result := Parameter.Get_Direction;
  162. end;
  163.  
  164. procedure TParameter.Set_Precision(pbPrecision: Byte);
  165. begin
  166.   Parameter.Precision := pbPrecision;
  167. end;
  168.  
  169. function  TParameter.Get_Precision: Byte;
  170. begin
  171.   Result := Parameter.Get_Precision;
  172. end;
  173.  
  174. procedure TParameter.Set_NumericScale(pbScale: Byte);
  175. begin
  176.   Parameter.NumericScale := pbScale;
  177. end;
  178.  
  179. function  TParameter.Get_NumericScale: Byte;
  180. begin
  181.   Result := Parameter.Get_NumericScale;
  182. end;
  183.  
  184. procedure TParameter.Set_Size(pl: Integer);
  185. begin
  186.   Parameter.Size := pl;
  187. end;
  188.  
  189. function  TParameter.Get_Size: Integer;
  190. begin
  191.   Result := Parameter.Get_Size;
  192. end;
  193.  
  194. function  TParameter.Get_Attributes: Integer;
  195. begin
  196.   Result := Parameter.Attributes;
  197. end;
  198.  
  199. procedure TParameter.Set_Attributes(plParmAttribs: Integer);
  200. begin
  201.   Parameter.Set_Attributes(plParmAttribs);
  202. end;
  203.  
  204. procedure TParameter.AppendChunk(Val: OleVariant);
  205. begin
  206.   Parameter.AppendChunk(Val);
  207. end;
  208.  
  209. end.
  210.