home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / dataflex / data_set.pkg < prev    next >
Encoding:
Text File  |  1993-08-10  |  9.2 KB  |  307 lines

  1. //************************************************************************
  2. //
  3. // Copyright 1987-1992 Data Access Corporation, Miami FL, USA
  4. // All Rights reserved
  5. // DataFlex is a registered trademark of Data Access Corporation.
  6. //
  7. //
  8. //     $Source: /u3/source.30/product/pkg/RCS/data_set.pkg,v $
  9. //     $Revision: 1.1 $
  10. //     $State: Exp $
  11. //     $Author: james $
  12. //     $Date: 1992/09/08 14:43:03 $
  13. //     $Locker:  $
  14. //
  15. //     $Log: data_set.pkg,v $
  16. //Revision 1.1  1992/09/08  14:43:03  james
  17. //Initial revision
  18. //
  19. //Revision 1.10  92/06/03  16:06:57  steve-l
  20. //altered BEGIN_CONSTRAINTS...END_CONSTRAINTS macros to forward last, not first
  21. //
  22. //Revision 1.9  92/05/14  16:08:27  SWM
  23. //Updated Copyright slug.
  24. //
  25. //Revision 1.8  92/04/21  18:07:17  steve-l
  26. //altered Item_Find to run constrained_clear on recbuf iff entUpdate did not
  27. //change it (i.e. recbuf is clear after entUpdt and before attach)
  28. //
  29. //Revision 1.7  92/04/01  18:26:30  steve-l
  30. //removed changes for rev. 1.6 (incorrect!)
  31. //
  32. //Revision 1.6  92/04/01  18:23:59  steve-l
  33. //altered Item_Find to convert LT/LE to LAST_RECORD and GT/GE to FIRST_RECORD
  34. //iff the record buffer is initially clear
  35. //
  36. //Revision 1.5  92/03/29  18:44:44  lee
  37. //added MSG_END_CONSTRUCT_OBJECT, moved ENDMAC macro stuff into END_CONSTRUCT-
  38. //OBJECT procedures (in .pkgs). moved Flag_ITems to list.pkg after generalizing
  39. //it based on PROTOTYPE_OBJECT instead of Whether or not it is a table-oriented
  40. //object. Moved define_access_keys mechanism completely into actionbr.pkg.
  41. //fixed two typos: import_class_protocol used !# instead of !3, and register-
  42. //procedure used !1 instead of !2.
  43. //
  44. //Revision 1.4  92/03/26  18:33:03  steve-l
  45. //altered item_find to properly hold recbuf before performing an attach
  46. //
  47. //Revision 1.3  92/03/09  19:00:50  james
  48. //Added #CHKSUB directive to insure source
  49. //only compiled with correct revision of 
  50. //compiler.
  51. //
  52. //Revision 1.2  92/03/05  15:45:51  steve-l
  53. //Item_Find changed to set ERR false before sending request_superfind,
  54. //request_Read, etc., and to check err (with found) afterward, in case of
  55. //non-file-boundary errors.
  56. //
  57. //Revision 1.1  91/10/23  10:19:58  elsa
  58. //Initial revision
  59. //
  60. //************************************************************************/
  61.  
  62. //************************************************************************
  63. //     File Name: Data_Set.Pkg
  64. // Creation Date: January 1, 1991
  65. // Modified Date: April 21, 1992
  66. //     Author(s): Steven A. Lowe
  67. //
  68. // This module contains the Data_Set class definition.
  69. //************************************************************************/
  70.  
  71.  
  72. #CHKSUB 2 1  // Verify the data_set subsystem.
  73.  
  74. use EnClient
  75.  
  76. #IFSUB 'NEXT_RECORD'
  77. #ELSE
  78.   #REPLACE NEXT_RECORD   5  /* find-next   */
  79.   #REPLACE FIRST_RECORD  6  /* find-first  */
  80.   #REPLACE LAST_RECORD   7  /* find-last   */
  81. #ENDIF
  82.  
  83.  
  84. #IFDEF OPERATION_MODE
  85. #ELSE
  86.   //
  87.   //Global integer status value
  88.   //
  89.   #REPLACE OPERATION_MODE |VI99  //status of data-sets in application
  90.   //
  91.   //Constants for Operation_Mode global int values
  92.   //
  93.   #REPLACE MODE_WAITING  0  //wait-mode  
  94.   #REPLACE MODE_FINDING  1  //find-mode  
  95.   #REPLACE MODE_CLEARING 2  //clear-mode 
  96.   #REPLACE MODE_CREATING 3  //create-mode
  97.   #REPLACE MODE_SAVING   4  //save-mode  
  98.   #REPLACE MODE_DELETING 5  //delete-mode
  99.   #REPLACE MODE_ABORTING 6  //abort-mode 
  100. #ENDIF
  101.  
  102.  
  103. //
  104. // Description
  105. //
  106. //   The Data_Set class is implemented as a subclass of Entry_Client, with
  107. //   a C language handler providing the majority of new behavior.  The
  108. //   Data_Set class is intended to be a grouping agent for data-entry objects
  109. //   and a container for subordinate Data_Sets.
  110. //
  111. // Assumptions/Preconditions
  112. //
  113. //   None.
  114. //
  115. // Exceptions
  116. //
  117. //   None.
  118. //
  119. // Notes
  120. //
  121. //  Syntax:
  122. //
  123. //  Object <name> is a Data_Set <image> {ACTION_BAR <ActionBar>} {POP_UP}
  124. //      {RING} {MAIN_FILE <Main_File> {BY <Index>} }
  125. //      {UPDATING <File> | <DataSetID> ... } }
  126. //   :
  127. //  End_Object
  128. //
  129. //  Data_Sets may be used to group DEOs as well as other Data_Sets.
  130. //  Note also that a nested (component) Data_Set automatically enforces an
  131. //  UPDATES visibility and a RELATES TO constraint between its main_file and
  132. //  its parent's main_file.
  133. //
  134.  
  135. Class Data_Set is an Entry_Client ;  //Data_Set inherits from Entry_Client
  136.     STARTMAC dsStart ;               //dsStart macro is used to handle syntax
  137.     0 0 ;                            //default colors
  138.     Data_Set_Handler                 //C-function for base class behavior
  139.  
  140.   !A [] $461 U_DATA_SET                //register C messages
  141.  
  142.   function Field_Main_Index integer file integer field returns integer
  143.     local integer dataType fldNdx retval ordr
  144.     move -1 to retval      //field has no main index (default)
  145.     if file ne 0 begin
  146.       FIELD_DEF file field to dataType fldNdx
  147.       if (fldNdx > 0 OR field = 0) move fldNdx to retval //field has main index
  148.     end
  149.     if file eq (main_file(current_object)) begin
  150.       get ordering to ordr
  151.       if ordr ge 0 move ordr to retval  //ordering takes precedence over main index
  152.     end
  153.     function_return retval
  154.   end_function
  155.  
  156.   procedure Item_Find FOR DATA_SET integer mode integer datafile integer datafield ;
  157.       integer entUpdtFlag integer errFlag integer dfrdFlag
  158.     local integer ndx rec wasChanged
  159.     move (Field_Main_Index(current_object,dataFile,datafield)) to ndx
  160.     if ndx GE 0 begin
  161.       move dataFile to FILENUMBER
  162.       move 0 to FIELDINDEX
  163.       //
  164.       //  'hold' buffer to prepare for entry_update
  165.       //
  166.       move Indirect_File.RECNUM to rec
  167.       move 0 to Indirect_File.RECNUM    //make buffer inactive but
  168.       move rec to Indirect_File.RECNUM  //replace record number
  169.       if entUpdtFlag ne 0 begin
  170.         send Request_Entry_Update dataFile 1  //entUpdt all DEOs as required
  171.  
  172.         //
  173.         // we really only need to know if any segment of the index changed
  174.         // but since we don't have field-changed flags, we look at the
  175.         // whole recbuf - this is consistent with 2.3b and 3.0 non-dataset
  176.         // behavior.
  177.         //
  178.         move (FALSE) to wasChanged
  179.         move dataFile to FILENUMBER
  180.         move 0 to FIELDINDEX
  181.         if Indirect_file.RECNUM ne 0 move (TRUE) to wasChanged
  182.         ifchange Indirect_File move (TRUE) to wasChanged
  183.         if wasChanged eq (FALSE) constrained_clear mode datafile by ndx
  184.  
  185.         if datafile eq (main_file(current_object)) ;
  186.             send attach_main_file
  187.         else begin
  188.           move dataFile to filenumber
  189.           move 0 to fieldindex
  190.           attach Indirect_File
  191.         end
  192.       end
  193.       indicate err false
  194.       if (Is_SuperFind_Required(current_object,dataFile)) ;
  195.           send Request_SuperFind mode dataFile datafield
  196.       else if dfrdFlag send Request_Read mode dataFile ndx
  197.       else send Request_Find mode dataFile ndx
  198.       [not found not err] begin
  199.         move 0 to FIELDINDEX
  200.         move dataFile to FILENUMBER
  201.         clear Indirect_File
  202.         move rec to Indirect_File.RECNUM
  203.         find eq Indirect_File.RECNUM
  204.         if errFlag ne 0 begin
  205.           if mode lt 2 error 41
  206.           else error 42
  207.         end
  208.         indicate FOUND FALSE
  209.       end
  210.     end
  211.     else if errFlag error 79
  212.   end_procedure
  213.  
  214.   procedure End_Construct_Object
  215.     if (Child_Count(current_object) le 0) set Focus_Mode to NONFOCUSABLE
  216.     forward send End_Construct_Object
  217.   end_procedure
  218.  
  219. end_class
  220.  
  221. //
  222. // Support Commands
  223. //
  224.  
  225. //
  226. //dsStart <className> <ImageName> {ACTION_BAR <ActionBar>} {POP_UP} {RING}
  227. //  {MAIN_FILE <Main_File> {BY <Index>} 
  228. //   {UPDATING <FileName> | <DataSetID> ... } }
  229. //
  230. // this macro handles the optional syntax of Data_Sets  
  231. //
  232. #COMMAND dsStart R R
  233.   FORWARD_BEGIN_CONSTRUCT !1 !2 !3 !4 !5 !6 !7 !8 !9
  234.   Bind_Main_File !3 !4 !5 !6 !7 !8 !9
  235.   Bind_Index !3 !4 !5 !6 !7 !8 !9
  236.   Bind_Updating !3 !4 !5 !6 !7 !8 !9
  237. #ENDCOMMAND
  238.  
  239. #COMMAND bind_main_file
  240.   #IF (!0>1)
  241.     #IFSAME !1 MAIN_FILE
  242.       #IFDEF !2.RECNUM
  243.         #PUSH !u
  244.         #SET U$ !2.RECNUM
  245.         set main_file to |CI!u
  246.         #POP u$
  247.       #ELSE
  248.         #ERROR 778 If !2 is a file it is unopened
  249.       #ENDIF
  250.     #ELSE
  251.       bind_main_file !2 !3 !4 !5 !6 !7 !8 !9
  252.     #ENDIF
  253.   #ENDIF
  254. #ENDCOMMAND
  255.  
  256. #COMMAND bind_index
  257.   #IF (!0>1)
  258.     #IFSAME !1 BY
  259.       set ordering to !2
  260.     #ELSE
  261.       bind_index !2 !3 !4 !5 !6 !7 !8 !9
  262.     #ENDIF
  263.   #ENDIF
  264. #ENDCOMMAND
  265.  
  266. #COMMAND Bind_Updating
  267.   #IF (!0>1)
  268.     #IFSAME !1 UPDATING
  269.       SetDependents !2 !3 !4 !5 !6 !7 !8 !9
  270.     #ELSE
  271.       Bind_Updating !2 !3 !4 !5 !6 !7 !8 !9
  272.     #ENDIF
  273.   #ENDIF
  274. #ENDCOMMAND
  275.  
  276. #COMMAND SetDependents   //<File>|<Server#> [ ... ]
  277.   #IF (!0>0)
  278.     #IFDEF !1
  279.       send Attach_Server !1
  280.     #ELSE
  281.       #IFDEF !1.OBJ
  282.         send attach_Server !1.OBJ
  283.       #ELSE
  284.         #IFDEF !1.RECNUM
  285.           #PUSH !u
  286.           #SET U$ !1.RECNUM
  287.           send Add_Parent_File |CI!u
  288.           #POP U$
  289.         #ELSE
  290.           #ERROR 778 If !1 is a file it is unopened
  291.         #ENDIF
  292.       #ENDIF
  293.     #ENDIF
  294.     SetDependents !2 !3 !4 !5 !6 !7 !8 !9
  295.   #ENDIF
  296. #ENDCOMMAND
  297.  
  298. #COMMAND BEGIN_CONSTRAINTS
  299.   procedure constrain
  300. #ENDCOMMAND
  301.  
  302. #COMMAND END_CONSTRAINTS
  303.     forward send constrain
  304.   end_procedure
  305. #ENDCOMMAND
  306.  
  307.