home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kolekce / d3456 / ALEXSOFT.ZIP / FRMDSRCE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-29  |  16.9 KB  |  589 lines

  1. (*////////////////////////////////////////////////////////////////////////////
  2. //   Part of AlexSoft VCL/DLL Library.                                      //
  3. //   All rights reserved. (c) Copyright 1998.                               //
  4. //   Created by: Alex Rabichooc                                             //
  5. //**************************************************************************//
  6. //  Users of this unit must accept this disclaimer of warranty:             //
  7. //    "This unit is supplied as is. The author disclaims all warranties,    //
  8. //    expressed or implied, including, without limitation, the warranties   //
  9. //    of merchantability and of fitness for any purpose.                    //
  10. //    The author assumes no liability for damages, direct or                //
  11. //    consequential, which may result from the use of this unit."           //
  12. //                                                                          //
  13. //  This Unit is donated to the public as public domain.                    //
  14. //                                                                          //
  15. //  This Unit can be freely used and distributed in commercial and          //
  16. //  private environments provided this notice is not modified in any way.   //
  17. //                                                                          //
  18. //  If you do find this Unit handy and you feel guilty for using such a     //
  19. //  great product without paying someone - sorry :-)                        //
  20. //                                                                          //
  21. //  Please forward any comments or suggestions to Alex Rabichooc at:        //
  22. //                                                                          //
  23. //  a_rabichooc@yahoo.com or alex@carmez.mldnet.com                         //
  24. /////////////////////////////////////////////////////////////////////////////*)
  25. {---------------------------------------------------------------------------
  26.   Extended DataSource Components.
  27.      properties
  28.        FormClassName: String;
  29.           Name of a class of the form, which edits (or shows) given DataSet.
  30.           Note:
  31.              This form should be inherited from TDBForm.
  32.        FormCaption: String;
  33.           A Caption of this Form.
  34.        ModalForm: boolean;
  35.           Determines whether this Form is a modal form or not.
  36. ----------------------------------------------------------------------------}
  37.  
  38. unit FrmDSrce;
  39.  
  40. interface
  41.  
  42. uses
  43.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  44.   Db, DbClient, DBTables, DBForms
  45.   {$IFNDEF VER120}
  46.   {$IFNDEF VER110},ADOdb
  47.   {$ENDIF}
  48.   {$ENDIF};
  49.  
  50. type
  51.   TRaTable = class(ttable)
  52.   private
  53.     FFormClass: TDBFormClass;
  54.     FFormClassName: String;
  55.     FFormCaption: String;
  56.     FModalForm: boolean;
  57.     FFreeOnClose: boolean;
  58.   protected
  59.     function GetFormClass: String;
  60.     procedure SetFormClass(Value: String);
  61.   public
  62.     property FormClass: TDBFormClass read FFormClass write FFormClass;
  63.   published
  64.     property FormClassName: String read GetFormClass write SetFormClass;
  65.     property FormCaption: String read FFormCaption write FFormCaption;
  66.     property ModalForm: Boolean read FModalForm write FModalForm;
  67.     property FreeOnClose: Boolean read FFreeOnClose write FFreeOnClose;
  68.   end;
  69.  
  70.   TRaQuery = class(TQuery)
  71.   private
  72.     FFormClass: TDBFormClass;
  73.     FFormClassName: String;
  74.     FFormCaption: String;
  75.     FModalForm: boolean;
  76.     FFreeOnClose: boolean;
  77.   protected
  78.     function GetFormClass: String;
  79.     procedure SetFormClass(Value: String);
  80.   public
  81.     property FormClass: TDBFormClass read FFormClass write FFormClass;
  82.   published
  83.     property FormClassName: String read GetFormClass write SetFormClass;
  84.     property FormCaption: String read FFormCaption write FFormCaption;
  85.     property ModalForm: Boolean read FModalForm write FModalForm;
  86.     property FreeOnClose: Boolean read FFreeOnClose write FFreeOnClose;
  87.   end;
  88.  
  89.   TRaStoredProc = class(TStoredProc)
  90.   private
  91.     FFormClass: TDBFormClass;
  92.     FFormClassName: String;
  93.     FFormCaption: String;
  94.     FModalForm: boolean;
  95.     FFreeOnClose: boolean;
  96.   protected
  97.     function GetFormClass: String;
  98.     procedure SetFormClass(Value: String);
  99.   public
  100.     property FormClass: TDBFormClass read FFormClass write FFormClass;
  101.   published
  102.     property FormClassName: String read GetFormClass write SetFormClass;
  103.     property FormCaption: String read FFormCaption write FFormCaption;
  104.     property ModalForm: Boolean read FModalForm write FModalForm;
  105.     property FreeOnClose: Boolean read FFreeOnClose write FFreeOnClose;
  106.   end;
  107.  
  108.   TRaClientDataSet = class(TClientDataSet)
  109.   private
  110.     FFormClass: TDBFormClass;
  111.     FFormClassName: String;
  112.     FFormCaption: String;
  113.     FModalForm: boolean;
  114.     FFreeOnClose: boolean;
  115.   protected
  116.     function GetFormClass: String;
  117.     procedure SetFormClass(Value: String);
  118.   public
  119.     property FormClass: TDBFormClass read FFormClass write FFormClass;
  120.   published
  121.     property FormClassName: String read GetFormClass write SetFormClass;
  122.     property FormCaption: String read FFormCaption write FFormCaption;
  123.     property ModalForm: Boolean read FModalForm write FModalForm;
  124.     property FreeOnClose: Boolean read FFreeOnClose write FFreeOnClose;
  125.   end;
  126.  
  127. {$IFNDEF VER120}
  128. {$IFNDEF VER110}
  129.   TRaADODataSet = class(TADODataSet)
  130.   private
  131.     FFormClass: TDBFormClass;
  132.     FFormClassName: String;
  133.     FFormCaption: String;
  134.     FModalForm: boolean;
  135.     FFreeOnClose: boolean;
  136.   protected
  137.     function GetFormClass: String;
  138.     procedure SetFormClass(Value: String);
  139.   public
  140.     property FormClass: TDBFormClass read FFormClass write FFormClass;
  141.   published
  142.     property FormClassName: String read GetFormClass write SetFormClass;
  143.     property FormCaption: String read FFormCaption write FFormCaption;
  144.     property ModalForm: Boolean read FModalForm write FModalForm;
  145.     property FreeOnClose: Boolean read FFreeOnClose write FFreeOnClose;
  146.   end;
  147.  
  148.   TRaADOTable = class(TADOTable)
  149.   private
  150.     FFormClass: TDBFormClass;
  151.     FFormClassName: String;
  152.     FFormCaption: String;
  153.     FModalForm: boolean;
  154.     FFreeOnClose: boolean;
  155.   protected
  156.     function GetFormClass: String;
  157.     procedure SetFormClass(Value: String);
  158.   public
  159.     property FormClass: TDBFormClass read FFormClass write FFormClass;
  160.   published
  161.     property FormClassName: String read GetFormClass write SetFormClass;
  162.     property FormCaption: String read FFormCaption write FFormCaption;
  163.     property ModalForm: Boolean read FModalForm write FModalForm;
  164.     property FreeOnClose: Boolean read FFreeOnClose write FFreeOnClose;
  165.   end;
  166.  
  167.   TRaADOQuery = class(TADOQuery)
  168.   private
  169.     FFormClass: TDBFormClass;
  170.     FFormClassName: String;
  171.     FFormCaption: String;
  172.     FModalForm: boolean;
  173.     FFreeOnClose: boolean;
  174.   protected
  175.     function GetFormClass: String;
  176.     procedure SetFormClass(Value: String);
  177.   public
  178.     property FormClass: TDBFormClass read FFormClass write FFormClass;
  179.   published
  180.     property FormClassName: String read GetFormClass write SetFormClass;
  181.     property FormCaption: String read FFormCaption write FFormCaption;
  182.     property ModalForm: Boolean read FModalForm write FModalForm;
  183.     property FreeOnClose: Boolean read FFreeOnClose write FFreeOnClose;
  184.   end;
  185.  
  186.   TRaADOStoredProc = class(TADOStoredProc)
  187.   private
  188.     FFormClass: TDBFormClass;
  189.     FFormClassName: String;
  190.     FFormCaption: String;
  191.     FModalForm: boolean;
  192.     FFreeOnClose: boolean;
  193.   protected
  194.     function GetFormClass: String;
  195.     procedure SetFormClass(Value: String);
  196.   public
  197.     property FormClass: TDBFormClass read FFormClass write FFormClass;
  198.   published
  199.     property FormClassName: String read GetFormClass write SetFormClass;
  200.     property FormCaption: String read FFormCaption write FFormCaption;
  201.     property ModalForm: Boolean read FModalForm write FModalForm;
  202.     property FreeOnClose: Boolean read FFreeOnClose write FFreeOnClose;
  203.   end;
  204.  
  205. {$ENDIF}
  206. {$ENDIF}
  207.  
  208. function GetFormClass(ADataSet: TDataSet): TDBFormClass;
  209. function GetFormCaption(ADataSet: TDataSet): String;
  210. function IsModalForm(ADataSet: TDataSet): Boolean;
  211. function MustFreeForm(ADataSet: TDataSet): Boolean;
  212.  
  213. implementation
  214.  
  215. function GetFormClass(ADataSet: TDataSet): TDBFormClass;
  216. begin
  217.    if ADataSet is TRaTable then
  218.       Result := (ADataSet as TRaTable).FormClass
  219.      else
  220.    if ADataSet is TRaQuery then
  221.       Result := (ADataSet as TRaQuery).FormClass
  222.      else
  223.    if ADataSet is TRaStoredProc then
  224.       Result := (ADataSet as TRaStoredProc).FormClass
  225.      else
  226.    if ADataSet is TRaClientDataSet then
  227.       Result := (ADataSet as TRaClientDataSet).FormClass
  228.      else
  229.       Result := nil;
  230. end;
  231.  
  232. function GetFormCaption(ADataSet: TDataSet): String;
  233. begin
  234.    if ADataSet is TRaTable then
  235.       Result := (ADataSet as TRaTable).FormCaption
  236.      else
  237.    if ADataSet is TRaQuery then
  238.       Result := (ADataSet as TRaQuery).FormCaption
  239.      else
  240.    if ADataSet is TRaStoredProc then
  241.       Result := (ADataSet as TRaStoredProc).FormCaption
  242.      else
  243.    if ADataSet is TRaClientDataSet then
  244.       Result := (ADataSet as TRaClientDataSet).FormCaption
  245.      else
  246.       Result := '';
  247. end;
  248.  
  249. function IsModalForm(ADataSet: TDataSet): Boolean;
  250. begin
  251.    if ADataSet is TRaTable then
  252.       Result := (ADataSet as TRaTable).ModalForm
  253.      else
  254.    if ADataSet is TRaQuery then
  255.       Result := (ADataSet as TRaQuery).ModalForm
  256.      else
  257.    if ADataSet is TRaStoredProc then
  258.       Result := (ADataSet as TRaStoredProc).ModalForm
  259.      else
  260.    if ADataSet is TRaClientDataSet then
  261.       Result := (ADataSet as TRaClientDataSet).ModalForm
  262.      else
  263.       Result := True;
  264. end;
  265.  
  266. function MustFreeForm(ADataSet: TDataSet): Boolean;
  267. begin
  268.   if ADataSet is TRaTable then
  269.      Result := (ADataSet as TRaTable).FreeOnClose
  270.     else
  271.   if ADataSet is TRaQuery then
  272.      Result := (ADataSet as TRaQuery).FreeOnClose
  273.     else
  274.   if ADataSet is TRaStoredProc then
  275.      Result := (ADataSet as TRaStoredProc).FreeOnClose
  276.     else
  277.   if ADataSet is TRaClientDataSet then
  278.      Result := (ADataSet as TRaClientDataSet).FreeOnClose
  279.     else
  280.      Result := True;
  281. end;
  282.  
  283. {TRaTable}
  284. procedure TRaTable.SetFormClass(Value: String);
  285. begin
  286.    if Value <> FFormClassName then
  287.    begin
  288.       FFormClassName := Value;
  289.       FFormClassName := GetFormClass;
  290.    end;
  291. end;
  292.  
  293. function TRaTable.GetFormClass: String;
  294. var AClass: TPersistentClass;
  295. begin
  296.    if not (csDesigning in ComponentState) then
  297.    begin
  298.       try
  299.         AClass := FindClass(FFormClassName);
  300.         if AClass.InheritsFrom(TDBForm) then
  301.           FFormClass := TDBFormClass(AClass)
  302.          else
  303.          begin
  304.             FFormClass := nil;
  305.             FFormClassName := '';
  306.          end;
  307.       except
  308.          on E: EClassNotFound do
  309.             begin
  310.               FFormClass := nil;
  311.               FFormClassName := '';
  312.             end
  313.            else
  314.              raise;
  315.       end;
  316.    end;
  317.    Result := FFormClassName;
  318. end;
  319.  
  320. {TRaQuery}
  321. procedure TRaQuery.SetFormClass(Value: String);
  322. begin
  323.    if Value <> FFormClassName then
  324.    begin
  325.       FFormClassName := Value;
  326.       FFormClassName := GetFormClass;
  327.    end;
  328. end;
  329.  
  330. function TRaQuery.GetFormClass: String;
  331. var AClass: TPersistentClass;
  332. begin
  333.    if not (csDesigning in ComponentState) then
  334.    begin
  335.       try
  336.         AClass := FindClass(FFormClassName);
  337.         if AClass.InheritsFrom(TDBForm) then
  338.           FFormClass := TDBFormClass(AClass)
  339.          else
  340.          begin
  341.             FFormClass := nil;
  342.             FFormClassName := '';
  343.          end;
  344.       except
  345.          on E: EClassNotFound do
  346.             begin
  347.               FFormClass := nil;
  348.               FFormClassName := '';
  349.             end
  350.            else
  351.              raise;
  352.       end;
  353.    end;
  354.    Result := FFormClassName;
  355. end;
  356.  
  357. {TRaStoredProc}
  358. procedure TRaStoredProc.SetFormClass(Value: String);
  359. begin
  360.    if Value <> FFormClassName then
  361.    begin
  362.       FFormClassName := Value;
  363.       FFormClassName := GetFormClass;
  364.    end;
  365. end;
  366.  
  367. function TRaStoredProc.GetFormClass: String;
  368. var AClass: TPersistentClass;
  369. begin
  370.    if not (csDesigning in ComponentState) then
  371.    begin
  372.       try
  373.         AClass := FindClass(FFormClassName);
  374.         if AClass.InheritsFrom(TDBForm) then
  375.           FFormClass := TDBFormClass(AClass)
  376.          else
  377.          begin
  378.             FFormClass := nil;
  379.             FFormClassName := '';
  380.          end;
  381.       except
  382.          on E: EClassNotFound do
  383.             begin
  384.               FFormClass := nil;
  385.               FFormClassName := '';
  386.             end
  387.            else
  388.              raise;
  389.       end;
  390.    end;
  391.    Result := FFormClassName;
  392. end;
  393.  
  394. {TRaClientDataSet}
  395. procedure TRaClientDataSet.SetFormClass(Value: String);
  396. begin
  397.    if Value <> FFormClassName then
  398.    begin
  399.       FFormClassName := Value;
  400.       FFormClassName := GetFormClass;
  401.    end;
  402. end;
  403.  
  404. function TRaClientDataSet.GetFormClass: String;
  405. var AClass: TPersistentClass;
  406. begin
  407.    if not (csDesigning in ComponentState) then
  408.    begin
  409.       try
  410.         AClass := FindClass(FFormClassName);
  411.         if AClass.InheritsFrom(TDBForm) then
  412.           FFormClass := TDBFormClass(AClass)
  413.          else
  414.          begin
  415.             FFormClass := nil;
  416.             FFormClassName := '';
  417.          end;
  418.       except
  419.          on E: EClassNotFound do
  420.             begin
  421.               FFormClass := nil;
  422.               FFormClassName := '';
  423.             end
  424.            else
  425.              raise;
  426.       end;
  427.    end;
  428.    Result := FFormClassName;
  429. end;
  430.  
  431. {$IFNDEF VER120}
  432. {$IFNDEF VER110}
  433. { TRaADODataSet }
  434.  
  435. procedure TRaADODataSet.SetFormClass(Value: String);
  436. begin
  437.    if Value <> FFormClassName then
  438.    begin
  439.       FFormClassName := Value;
  440.       FFormClassName := GetFormClass;
  441.    end;
  442. end;
  443.  
  444. function TRaADODataSet.GetFormClass: String;
  445. var AClass: TPersistentClass;
  446. begin
  447.    if not (csDesigning in ComponentState) then
  448.    begin
  449.       try
  450.         AClass := FindClass(FFormClassName);
  451.         if AClass.InheritsFrom(TDBForm) then
  452.           FFormClass := TDBFormClass(AClass)
  453.          else
  454.          begin
  455.             FFormClass := nil;
  456.             FFormClassName := '';
  457.          end;
  458.       except
  459.          on E: EClassNotFound do
  460.             begin
  461.               FFormClass := nil;
  462.               FFormClassName := '';
  463.             end
  464.            else
  465.              raise;
  466.       end;
  467.    end;
  468.    Result := FFormClassName;
  469. end;
  470.  
  471. { TRaADOTable }
  472.  
  473. procedure TRaADOTable.SetFormClass(Value: String);
  474. begin
  475.    if Value <> FFormClassName then
  476.    begin
  477.       FFormClassName := Value;
  478.       FFormClassName := GetFormClass;
  479.    end;
  480. end;
  481.  
  482. function TRaADOTable.GetFormClass: String;
  483. var AClass: TPersistentClass;
  484. begin
  485.    if not (csDesigning in ComponentState) then
  486.    begin
  487.       try
  488.         AClass := FindClass(FFormClassName);
  489.         if AClass.InheritsFrom(TDBForm) then
  490.           FFormClass := TDBFormClass(AClass)
  491.          else
  492.          begin
  493.             FFormClass := nil;
  494.             FFormClassName := '';
  495.          end;
  496.       except
  497.          on E: EClassNotFound do
  498.             begin
  499.               FFormClass := nil;
  500.               FFormClassName := '';
  501.             end
  502.            else
  503.              raise;
  504.       end;
  505.    end;
  506.    Result := FFormClassName;
  507. end;
  508.  
  509. { TRaADOQuery }
  510.  
  511. procedure TRaADOQuery.SetFormClass(Value: String);
  512. begin
  513.    if Value <> FFormClassName then
  514.    begin
  515.       FFormClassName := Value;
  516.       FFormClassName := GetFormClass;
  517.    end;
  518. end;
  519.  
  520. function TRaADOQuery.GetFormClass: String;
  521. var AClass: TPersistentClass;
  522. begin
  523.    if not (csDesigning in ComponentState) then
  524.    begin
  525.       try
  526.         AClass := FindClass(FFormClassName);
  527.         if AClass.InheritsFrom(TDBForm) then
  528.           FFormClass := TDBFormClass(AClass)
  529.          else
  530.          begin
  531.             FFormClass := nil;
  532.             FFormClassName := '';
  533.          end;
  534.       except
  535.          on E: EClassNotFound do
  536.             begin
  537.               FFormClass := nil;
  538.               FFormClassName := '';
  539.             end
  540.            else
  541.              raise;
  542.       end;
  543.    end;
  544.    Result := FFormClassName;
  545. end;
  546.  
  547. { TRaADOStoredProc }
  548.  
  549. procedure TRaADOStoredProc.SetFormClass(Value: String);
  550. begin
  551.    if Value <> FFormClassName then
  552.    begin
  553.       FFormClassName := Value;
  554.       FFormClassName := GetFormClass;
  555.    end;
  556. end;
  557.  
  558. function TRaADOStoredProc.GetFormClass: String;
  559. var AClass: TPersistentClass;
  560. begin
  561.    if not (csDesigning in ComponentState) then
  562.    begin
  563.       try
  564.         AClass := FindClass(FFormClassName);
  565.         if AClass.InheritsFrom(TDBForm) then
  566.           FFormClass := TDBFormClass(AClass)
  567.          else
  568.          begin
  569.             FFormClass := nil;
  570.             FFormClassName := '';
  571.          end;
  572.       except
  573.          on E: EClassNotFound do
  574.             begin
  575.               FFormClass := nil;
  576.               FFormClassName := '';
  577.             end
  578.            else
  579.              raise;
  580.       end;
  581.    end;
  582.    Result := FFormClassName;
  583. end;
  584. {$ENDIF}
  585. {$ENDIF}
  586.  
  587. end.
  588.  
  589.