home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase Pro v7.0 / DATA1.CAB / Sample_dBASE / Editbar.prg < prev    next >
Encoding:
Text File  |  1997-11-20  |  3.4 KB  |  118 lines

  1. //------------------------------------------------------------------------
  2. //
  3. //  editbar.prg
  4. //
  5. //  Toolbar with rowset editing tool buttons.
  6. //  To use:
  7. /* 
  8.      f = new FishBarsForm()      // a form with a defined rowset
  9.      DO editbar.prg WITH f       // for small tool buttons
  10.      DO editbar.prg WITH f, true // for large tool buttons
  11. */
  12. //  
  13. //  Visual dBASE Samples Group
  14. //
  15. //  $Revision:   1.5  $
  16. //
  17. //  Copyright (c) 1997, Borland International, Inc. All rights reserved.    
  18. //
  19. //------------------------------------------------------------------------  
  20.  
  21.    parameter FormObj, bLarge
  22.    local t, bNew
  23.    t    = null
  24.    bNew = false
  25.    if ( PCOUNT() == 0 )
  26.       MSGBOX("To attach this toolbar to a form use: " + ;
  27.               CHR(13) + CHR(13) + ;
  28.              "DO " + PROGRAM() + " WITH <form reference>","Alert")
  29.    else
  30.       t := FindInstance("EditToolbar")
  31.       if ( ( t == null ) or ( not FormObj.mdi ) )
  32.          SET PROCEDURE TO (PROGRAM()) ADDITIVE
  33.          t = new EditToolbar( bLarge )
  34.          bNew := true
  35.       endif
  36.       t.attach( FormObj )  
  37.    endif
  38.  
  39. return ( bNew )
  40.  
  41. class EditToolbar( bLarge ) of Toolbar
  42.    local sBitsize
  43.    sBitsize = IIF( bLarge, "TL_", "TS_" )
  44.  
  45.    this.flat     := true
  46.    this.text     := "Edit"
  47.    this.onUpdate := class::edit_onUpdate
  48.  
  49.    this.tAppend = new ToolButton( this )
  50.    with ( this.tAppend )
  51.         bitmap   := "RESOURCE " + sBitsize + "APPEND"
  52.         speedTip := "Add Row"
  53.         onClick  := class::tAppend_onClick
  54.    endwith
  55.  
  56.    this.tDelete = new ToolButton( this )
  57.    with ( this.tDelete )
  58.         bitmap   := "RESOURCE " + sBitsize + "DELETE"
  59.         speedTip := "Delete Row"
  60.         onClick  := class::tDelete_onClick
  61.    endwith
  62.    
  63.    this.tSave = new ToolButton( this )
  64.    with ( this.tSave )
  65.         bitmap   := "RESOURCE " + sBitsize + "SAVE"
  66.         speedTip := "Save Row"
  67.         onClick  := class::tSave_onClick
  68.    endwith
  69.  
  70.    this.tAbandon = new ToolButton( this )
  71.    with ( this.tAbandon )
  72.         bitmap   := "RESOURCE " + sBitsize + "ABANDON"
  73.         speedTip := "Abandon Row"
  74.         onClick  := class::tAbandon_onClick
  75.    endwith
  76.  
  77.    function edit_onUpdate
  78.       LOCAL bRowFound
  79.       bRowFound = ( TYPE("this.form.rowset") == "O" )
  80.       this.tAppend.enabled  := bRowFound
  81.       this.tDelete.enabled  := bRowFound
  82.       this.tSave.enabled    := bRowFound
  83.       this.tAbandon.enabled := bRowFound
  84.    return ( bRowFound )
  85.  
  86.    function tAppend_onClick
  87.    return ( this.parent.form.rowset.beginAppend() )
  88.  
  89.    function tDelete_onClick
  90.       local bDelete, bFirst
  91.       bDelete = false
  92.       bFirst  = false
  93.       if ( not this.parent.form.rowset.endOfSet )
  94.          if ( MSGBOX("You are about to delete the current row." ;
  95.                    + CHR(13) ;
  96.                    + "Click Yes to delete the current row.", ;
  97.                      "Alert", ;
  98.                      4) == 6 )
  99.             bFirst  := this.parent.form.rowset.atFirst()
  100.             bDelete := this.parent.form.rowset.delete()       
  101.             if ( not bFirst ) 
  102.                this.parent.form.rowset.next(-1)
  103.             endif
  104.             if ( this.parent.form.rowset.endOfSet )
  105.                this.parent.form.rowset.next()
  106.             endif
  107.          endif
  108.       endif
  109.    return ( bDelete )
  110.  
  111.    function tSave_onClick
  112.    return ( this.parent.form.rowset.save() )
  113.  
  114.    function tAbandon_onClick
  115.    return ( this.parent.form.rowset.abandon() )
  116.  
  117. endclass
  118.