Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>frm_save() writes (.dbf) and (.mem) files to (.frm) file rlback.prg</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Frm_save()     Writes (.dbf) and (.mem) files to (.frm) file    Rlback.prg


Syntax:        Frm_save(<frm_file>, <dbf_file>, <mem_file>)

Argument:      <frm_file> is the name of the destination REPORT
               FORM.

               <dbf_file> is the name of the database file
               containing the column expressions.

               <mem_file> is the name of the memory file containing
               the report specifications.


Returns:       True (.T.) if the write operation was successful.

Calls:         Write_expr(), Write_field(), Write_params()

Notes:         . Report file name has extension.
               . File error number placed in file_error.
               . Offsets start are from 0.
               . Offsets are into a DOS FILE, 0 to 1989
               . Offsets mentioned in these notes are actual DOS FILE
                 offsets.  These ARE NOT the same as those declared in
                 FRM_LOAD().  An exception to this is the fields
                 (columns) related offsets which are relative to the
                 FIELDS_OFFSET offset.

               . Report file length is 7C6h (1990d) bytes.
               . Expression length array starts at 04h (4d) and can
                 contain upto 55 short (2 byte) numbers.

               . Expression offset index array starts at 72h (114d) and
                 can contain upto 55 short (2 byte) numbers.

               . Expression area starts at offset E0h (224d).
               . Expression area length is 5A0h (1440d).
               . Expressions in expression area are null terminated.
               . Expression lengths include the null terminator.
               . Field expression area starts at offset 680h (1664d).
               . Field expressions (column definition) are null
                 terminated.
               . Field expression area can contain upto 25 12 byte
                 elements describing a column layout.


--------------------------------- Source Code ------------------------------

   FUNCTION FRM_SAVE

   PARAMETERS report_file, dbf_file, mem_file

   ** Shared by FRM_SAVE() and its ancillary functions **
   PRIVATE handle, expr_offset, offsets_offset, lengths_offset,;
      fields_offset, page_hdr_num, grp_expr_num, sub_expr_num,;
      grp_hdr_num, sub_hdr_num, next_free_offset, last_expr, expr_count

   PRIVATE report_size, report_image, status, expr_count, i, j,;
      write_count, frm_pagehdr, frm_grpexpr, frm_subexpr, frm_grphdr,;
      frm_subhdr, frm_pagewidth, frm_linespage, frm_leftmarg,;
      frm_rightmarg, frm_colcount, frm_dblspaced, frm_summary,;
      frm_pe, frm_pebp, frm_peap, frm_plainpage

   report_size  = 1990         && size of report file.
   report_image = ""

   i           = 0
   j           = 0
   handle      = 0
   write_count = 0             && read/write and content record counter.
   status      = .F.

   expr_num   = 0              && expression record count.
   last_expr  = 0              && end of last expression in area + 1.
   expr_count = -1             && first expression at offset 0.

   ** Offsets into the report file **
   next_free_offset = 2        && first un-USEd expr area offset.
   lengths_offset   = 4        && start of expression length array.
   offsets_offset   = 114      && start of expression position array.
   expr_offset      = 224      && start of expression data area.
   fields_offset    = 1664     && start of report columns (fields).
   end_offset       = 1964     && start of last 24 bytes to write.

   ** Offsets array index numbers to these expressions **
   page_hdr_num = 0
   grp_expr_num = 0
   sub_expr_num = 0
   grp_hdr_num  = 0
   sub_hdr_num  = 0

   ** Create the label file **
   handle = FCREATE(report_file)

   ** Open ok? **
   file_error = FERROR()
   IF file_error = 0
      ** Restore report dimension values **
      RESTORE ADDITIVE FROM &mem_file

      ** Write a NULL filled report 'skeleton' **
      report_image = CHR(2) + CHR(0) + replicate(CHR(0), (1990 - 4)) +;
                        CHR(2) + CHR(0)
      write_count = FWRITE(handle, report_image, report_size)

      ** Skeleton WRITE ok? **
      IF write_count = 0
         file_error = -2
      ELSE
         file_error = FERROR()
      ENDIF

      IF file_error = 0

         ** Write Page Heading info **
         page_hdr_num = WRITE_EXPR(frm_pagehdr, .T.)

         ** WRITE ok? **
         IF page_hdr_num != -1

            ** Write Grouping expression info **
            grp_expr_num = WRITE_EXPR(frm_grpexpr, .T.)

            ** WRITE ok? **
            IF grp_expr_num != -1

               ** Write Sub-grouping expression info **
               sub_expr_num = WRITE_EXPR(frm_subexpr, .T.)

               ** WRITE ok? **
               IF sub_expr_num != -1

                  ** Write Group Heading info **
                  grp_hdr_num = WRITE_EXPR(frm_grphdr, .T.)

                  ** WRITE ok? **
                  IF grp_hdr_num != -1

                     ** Write Sub-group Heading info **
                     sub_hdr_num = WRITE_EXPR(frm_subhdr, .F.)

                     ** WRITE ok? **
                     status = (sub_hdr_num != -1)

                  ENDIF
               ENDIF
            ENDIF
         ENDIF

         ** Headers, grouping and sub-group info written ok? **
         IF status

            ** Write FIELDS (columns) info **
            USE &dbf_file
            j = lastrec()
            FOR i = 1 to j
               ** Write contents of FIELDS record to report file.
               status = WRITE_FIELD()

               ** Ok? **
               IF status
                  SKIP                    && pass, go next.
               ELSE
                  i = j + 1               && error, break out.
               ENDIF
            NEXT
            CLOSE DATABASES
         ENDIF

         ** Column info written ok? **
         IF status
            ** Write last 24 bytes of report and update next_free_offset **
            status = WRITE_PARAMS()
         ENDIF
      ENDIF

      ** CLOSE ok? **
      IF !FCLOSE(handle)
         file_error = FERROR()
         status = .F.
      ENDIF
   ENDIF

   RETURN (status)

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson