Here is some code that shows the correct way to do what you want.
This uses no private variables and no macros.
Just compile and run it.
Code: Select all
#INCLUDE "dcdialog.CH"
#INCLUDE "appevent.CH"
FUNCTION Main()
LOCAL GetList[0], GetOptions, cName, aPerformers[6], lImmediate, ;
aNames[6], nRow := 1, bBlock, i
AFill(aPerformers,Space(30))
AFill(aNames,PerformerNames())
FOR i := 1 TO Len(aPerformers)
bBlock := AnchorBlock( @aPerformers[i], @aNames[i] )
@ nRow,0 DCSAY 'Enter Performer Name' GET aPerformers[i] ;
SAYSIZE 0 SAYBOTTOM ;
KEYBLOCK bBlock ;
COMBO HEIGHT 10 DATA aNames[i]
nRow += 2
NEXT
lImmediate := DC_GetComboImmediate(.t.)
DCREAD GUI FIT TITLE 'Scoped Drop-Down' MODAL ADDBUTTONS
DC_GetComboImmediate(lImmediate)
wtf aPerformers pause
RETURN nil
* -----------
STATIC FUNCTION AnchorBlock( cPerformer, aNames )
RETURN {|a,b,o|DropDownNames(a,b,o,@cPerformer,@aNames)}
* -----------
STATIC FUNCTION DropDownNames( nKey, mp2, oGet, cPerformer, aNames )
LOCAL nFound, cName, nLen := Len(cPerformer), aPerformers
IF Chr(nKey) < 'A' .OR. Chr(nKey) > 'z'
RETURN nil
ENDIF
oGet:getData()
cName := Alltrim(Upper(cPerformer))
ASize(aNames,0)
aPerformers := PerformerNames()
nFound := AScan( aPerformers, {|c|Alltrim(Upper(c)) = cName} )
IF nFound > 0
DO WHILE nFound <= Len(aPerformers) .AND. Alltrim(Upper(aPerformers[nFound])) = cName
AAdd( aNames, aPerformers[nFound])
nFound++
ENDDO
oGet:comboData := aNames // store scoped array to datasource
PostAppevent(xbeP_Activate,,,oGet:popupButton) // popup scoped dropdown
SetAppFocus(oGet)
DC_CompleteEvents()
ENDIF
oGet:comboData := aPerformers // store full array to datasource
IF Empty(aNames)
AAdd(aNames,'')
ENDIF
RETURN nil
* -------
PROC appsys ; RETURN
* -------
STATIC FUNCTION PerformerNames()
RETURN { ;
'Annie Hall', ;
'Arlo Guthrie', ;
'Bette Midler', ;
'Bob Dylan', ;
'Bobbie Gentry', ;
'Buddy Holly', ;
'Canned Heat', ;
'Carol Elliot', ;
'Carole King', ;
'Caroline Aikin', ;
'Cat Stevens', ;
'Catie Curtis', ;
'Cheryl Wheeler', ;
'Chuck Prophet', ;
'Chuck Pyle', ;
'Crosby, Stills, Nash', ;
'Danny Kaye', ;
'Dar Williams', ;
'Dr Hook', ;
'Eliza Gilkyson', ;
'Elton John', ;
'Elvis Presley', ;
'Gail Davies', ;
'Glenn Miller', ;
'Gordon Rowland', ;
'Greg Brown', ;
'Harry McClintock', ;
'Itzhak Perlman', ;
'James Taylor', ;
'Jan Stanfield', ;
'Jefferson Airplane', ;
'Jim Croce', ;
'Jimi Hendrix', ;
'Jimmy Dean', ;
'John Denver', ;
'Joni Mitchell', ;
'Journey', ;
'Kevin Welch', ;
'Krystian Zimermann', ;
'Led Zeppelin', ;
'Lyle Lovett', ;
'Lynn Miles', ;
'Madeleine Peyroux', ;
'Michael Jackson', ;
'Michael Lille', ;
'Mumbo Gumbo', ;
'Norah Jones', ;
'Ray Charles', ;
'Richard Pryor', ;
'Richard Shindell', ;
'Richie Havens', ;
'Robin Williams', ;
'Roy Orbison', ;
'Sam Cooke', ;
'Slobberbone', ;
'Steppenwolf', ;
'Susan Werner', ;
'Ten Years After', ;
'The Beatles', ;
'The Doors', ;
'The Eagles', ;
'The Flatlanders', ;
'The Moody Blues', ;
'Tim Bays', ;
'Toby Keith', ;
'Tom Paxton', ;
'Tom Petty', ;
'Tom Prasada-Rao', ;
'Van Morrison', ;
'Vance Gilbert', ;
'Vic Chestnutt', ;
'Willie Nelson', ;
'Yo-yo Ma', ;
'Yundi Li'}