Author: Ed Leafe
Posted: 1998-06-25 at 17:24:28
<I><FONT COLOR="#663300">Sure... every little bit helps... Does it generate the code book menus using cMenu,cPad,cPopup methods?</FONT></I>
Not exactly - what it does is use a table to dynamically create the aChildren() arrays at run time. I'm including the class export code below. Bear in mind that this was for a 3.0 app and was written over 2.5 years ago!
**************************************************
*-- Class: tablepopup (f:cdbk30fislibsamenus.vcx)
*-- ParentClass: cpopup (f:cdbk30common30libscmenus.vcx)
*-- BaseClass: container
*
#INCLUDE "f:cdbk30fisincludeappincl.h"
*
DEFINE CLASS tablepopup AS cpopup
Width = 173
Height = 25
*-- Alias from which the popup bars are selected
calias = ""
*-- Filter expression to be used when selecting from the alias
cfilter = ""
*-- Name of the field used to populate the popup bars
cfldname = ""
*-- Field in the cAlias table containing the unique ID of the selected bar's record.
cidfld = ""
*-- name of the class of the bars to add.
cbarclass = ""
*-- The value to be passed to the child bars when a "New..." bar is selected.
cnewid = ("000000")
*-- Name of directory to find the table for the cAlias property.
cdatadir = "DATA"
Name = "tablepopup"
*-- If .T., adds a bar with the word "New..." to the popup
laddnewbar = .F.
*-- If .T., the bar labelled "New..." is placed at the top of the popup
lnewbarontop = .F.
*-- Array which holds additional info about the bars to be created. Its rows match with those in the aChildren property.
DIMENSION achildinfo[1,2]
PROCEDURE loadchildren
LOCAL lcDataDir, lcAlias, lcFilter, lcFldName, lcIDFld, laBars[1], lnTally, ;
llNewBar, llNewTop, lnOffset
IF TYPE("goApp") = "O"
lcDataDir = goApp.GetSetting('DBC Locations - Local', 'CDBK30')
ELSE
lcDataDir = This.cDataDir
ENDIF
lcAlias = This.cAlias
IF !USED(lcAlias)
USE (lcDataDir + "" + lcAlias + ".DBF") IN 0 ALIAS &lcAlias
ENDIF
lcFilter = IIF(EMPTY(This.cFilter), "", ;
"WHERE " + This.cFilter)
lcFldname = This.cFldName
lcIDFld = This.cIDFld
llNewBar = This.lAddNewbar
llNewTop = This.lNewBarOnTop
lnOffset = IIF(llNewBar AND llNewTop, 1, 0)
SELECT &lcFldName, &lcIDFld ;
FROM &lcAlias ;
&lcFilter ;
INTO ARRAY laBars
lnTally = _TALLY + IIF(llNewBar, 1, 0)
LOCAL laChildren[lnTally, ALEN(this.aChildren,2)], ;
laChildInfo[lnTally, 3], lnCnt, lcBarClass, ;
lnBarRow
#DEFINE CHILD_CAPTION 1
#DEFINE CHILD_ID 2
#DEFINE CHILD_NEW 3
lcBarClass = This.cBarClass
IF llNewbar
lnCnt = IIF(llNewTop, 1, lnTally)
laChildren[lnCnt, CHILD_CLASS] = lcBarClass
laChildren[lnCnt, CHILD_NAME] = "o" + ;
lcBarClass + ALLTRIM(STR(lnCnt))
laChildInfo[lnCnt, CHILD_CAPTION] = "New..."
laChildInfo[lnCnt, CHILD_ID] = This.cNewID
laChildInfo[lnCnt, CHILD_NEW] = .T.
ENDIF
lnBarRow = 0
LOCAL lnLo, lnHi
lnLo = (1 + lnOffset)
lnHi = lnTally - IIF(llNewbar, (1-lnOffSet), 0)
FOR lnCnt = lnLo TO lnHi
lnBarRow = lnBarRow + 1
laChildren[lnBarRow, CHILD_CLASS] = lcBarClass
laChildren[lnBarRow, CHILD_NAME] = "o" + lcBarClass + ALLTRIM(STR(lnCnt))
laChildInfo[lnBarRow, CHILD_CAPTION] = ALLTRIM(laBars[lnBarRow, CHILD_CAPTION])
laChildInfo[lnBarRow, CHILD_ID] = ALLTRIM(laBars[lnBarRow, CHILD_ID])
laChildInfo[lnCnt, CHILD_NEW] = .F.
ENDFOR
DIMENSION This.aChildren[lnTally, ALEN(laChildren,2)], This.aChildInfo[lnTally, ALEN(laChildInfo,2)]
=ACOPY(laChildren, This.aChildren)
=ACOPY(laChildInfo, This.aChildInfo)
RETURN lnTally
ENDPROC
PROCEDURE createchildren
#DEFINE CHILD_CAPTION 1
#DEFINE CHILD_ID 2
#DEFINE CHILD_NEW 3
*-- Iterates through the aChildren[] array adding each object
*-- to the collection using this.Add()
LOCAL lnChild, ;
laChildren[ALEN(this.aChildren, 1), ALEN(this.aChildren, 2)], ;
laChildInfo[ALEN(this.aChildInfo, 1), ALEN(this.aChildInfo, 2)]
=ACOPY(this.aChildren, laChildren)
=ACOPY(this.aChildInfo, laChildInfo)
FOR lnChild = 1 TO ALEN(laChildren, 1)
*-- Create default name for object if not specified
IF TYPE("laChildren[lnChild, " + ALLT(STR(CHILD_NAME)) + "]") <> "C"
laChildren[lnChild, CHILD_NAME] = ;
"o" + laChildren[lnChild, CHILD_CLASS]
ENDIF
IF !this.Add( laChildren[lnChild, CHILD_NAME], ;
laChildren[lnChild, CHILD_CLASS], ;
laChildInfo[lnChild, CHILD_CAPTION], ;
laChildInfo[lnChild, CHILD_ID], ;
laChildInfo[lnChild, CHILD_NEW])
RETURN .F.
ENDIF
ENDFOR
ENDPROC
ENDDEFINE
*
*-- EndDefine: tablepopup
**************************************************
<font color="#cc0000"> ___/
/
__/
/
____/</font>
Ed Leafe