>CLEAR >CLOSE ALL >CLEAR ALL > >*--For testing purposes, remove the collection if it already exists >IF PEMSTATUS(_SCREEN,'myConnections',5) > REMOVEPROPERTY(_SCREEN,'myConnections') >ENDIF > >PUBLIC lctblconnsConn >lctblconnsConn="Data_Hqq" >SET CLASSLIB TO SQLClss ADDITIVE > >*--Open the table containing the connection information && Left out scan for testing purposes only >lcTable = GETFILE('dbf','File Name','Select',1,'Locate the connections configuration table') >IF !EMPTY(lcTable) > USE (lcTable) ALIAS tblconns >ENDIF >IF EMPTY(ALIAS()) > RETURN >ENDIF >SET DELETED ON >? [ ============================================================= ] >? [ * Table Used for Connection Information: ] + DBF() >IF !PEMSTATUS(_SCREEN,'myConnections',5) && Collection property to store connections > _SCREEN.ADDPROPERTY('myConnections',NEWOBJECT('Collection')) >ENDIF >lctblconnsConn = UPPER('' + TRIM(tblconns.product) + "_" + TRIM(tblconns.agency)) >? [* Working on Connection: ] + lctblconnsConn >PUBLIC &lctblconnsConn >SET CLASSLIB TO SQLClss ADDITIVE >PUBLIC lckey >lckey = lctblconnsConn >&lctblconnsConn= CREATEOBJECT("SQLCLSS.SQLPROC") && Create Connection Object >loSqlControl = EVALUATE(m.lctblconnsConn) >? [ ============================================================= ] >? [ * Store values to connection object ] >IF TYPE('loSqlControl') = "O" .AND. !ISNULL(loSqlControl) > STORE TRIM(tblconns.SERVERNAME) TO (lctblconnsConn+'.pcServer') > STORE TRIM(tblconns.DATABASE) TO (lctblconnsConn+'.pcdatabase') > STORE TRIM(tblconns.USERID) TO (lctblconnsConn+'.pcUser') > STORE " " TO (lctblconnsConn+'.pcPassword') && testing > STORE tblconns.engine TO (lctblconnsConn+'.pnEngine') > STORE lctblconnsConn TO (lctblconnsConn+'.name') > IF !PEMSTATUS(_SCREEN.myConnections,lctblconnsConn,5) && Add this conn object to connection > _SCREEN.myConnections.ADD(loSqlControl,lckey) > ENDIF > ? [ * Successfully stored values to connection object properties ] >ELSE > ? [ ************************************************************* ] > ? [ Unable to access ] + lctblconnsConn + [ object. ] > ? [ ************************************************************* ] >ENDIF >? [ ============================================================= ] >? [ * See if connection objects exist in the collection using For Each...] >FOR EACH oControl IN _SCREEN.myConnections FOXOBJECT > ? oControl.NAME > ? oControl.pcServer > ? oControl.pcDatabase > ? oControl.pcPassword > ? oControl.pcUser > ? oControl.pnEngine >ENDFOR >? [* See if the connection object itself exists and display its properties] >? [ ============================================================= ] >IF TYPE('loSqlControl') = "O" .AND. !ISNULL(loSqlControl) > ? (lctblconnsConn+'.pcServer') + "=" + EVALUATE(lctblconnsConn+'.pcServer') > ? (lctblconnsConn+'.pcdatabase')+ "=" + EVALUATE(lctblconnsConn+'.pcdatabase') > ? (lctblconnsConn+'.pcUser') + "=" + EVALUATE(lctblconnsConn+'.pcUser') > ? (lctblconnsConn+'.pcPassword')+ "=" + EVALUATE(lctblconnsConn+'.pcdatabase') > ? (lctblconnsConn+'.pnEngine') + "=" + ALLTRIM(STR(EVALUATE(lctblconnsConn+'.pnEngine'))) > ? (lctblconnsConn+'.name') + "=" + EVALUATE(lctblconnsConn+'.name') >ELSE > ? [ ************************************************************* ] > ? [ * Object does not exist ] > ? [ ************************************************************* ] >ENDIF > >? [ ============================================================= ] >? [ * Test verifying using different references: ] >? _SCREEN.myConnections('DATA_HQQ').NAME && Returns the correct value >? _SCREEN.myConnections(lctblconnsConn).NAME && Returns the correct value >? _SCREEN.myConnections(lckey).NAME && Returns the correct value >?[ * Does the Data_Hqq connection object exist? ] >? PEMSTATUS(_SCREEN,'myConnections',5) && Returns .T. the collection exists >? TYPE(lctblconnsConn) ="O" .AND. !ISNULL(lctblconnsConn) && Returns .T. the actual connection exists >? _SCREEN.myConnections.GETKEY(lctblconnsConn) && Returns 1 - the index connection in the collection? >? _SCREEN.myConnections.GETKEY(1) && Returns Data_Hqq >? [ ============================================================= ] >? [ * Store connection information to an array ] >LOCAL llNoaConn >llNoaConn = .F. >IF !PEMSTATUS(_SCREEN,'aConnections',5) > IF !_SCREEN.ADDPROPERTY('aConnections(1,9)','') > llNoaConn = .T. > ELSE > _SCREEN.aConnections(1,8) = 0 && Engine > _SCREEN.aConnections(1,9) = 0 && connection number > ENDIF >ELSE > *--Don't allow duplicate connection objects if tblconns.prg is called more than once > IF TYPE('ALEN(_Screen.aConnections,1)') = "N" && Valid array screen property > *--Release all connection objects > FOR iloop = 1 TO ALEN(_SCREEN.aConnections,1) > IF TYPE('_Screen.aConnections(iloop,1)') <> "U" > RELEASE (_SCREEN.aConnections(iloop,1)) > ENDIF > ENDFOR > ENDIF > DIMENSION _SCREEN.aConnections(1,9) > _SCREEN.aConnections = '' && Most items are string > _SCREEN.aConnections(1,8) = 0 && Engine is numeric > _SCREEN.aConnections(1,9) = 0 && Connection number is numeric >ENDIF >IF !llNoaConn .AND. PEMSTATUS(_SCREEN,'aConnections',5) > lnConnNbr = 0 && Fake number for testing only > IF TYPE('_Screen.aConnections(ALEN(_Screen.aConnections,1),1)') = "O" && Oops > _SCREEN.aConnections(ALEN(_SCREEN.aConnections,1),1) = '' && Reuse this one > ENDIF > IF TYPE('_screen.aConnections(ALEN(_screen.aConnections,1),1)') <> "L" .AND. !EMPTY(_SCREEN.aConnections(ALEN(_SCREEN.aConnections,1),1)) > DIMENSION _SCREEN.aConnections(ALEN(_SCREEN.aConnections,1)+1,9) > ENDIF > _SCREEN.aConnections(ALEN(_SCREEN.aConnections,1),1) = lctblconnsConn && string > _SCREEN.aConnections(ALEN(_SCREEN.aConnections,1),2) = TRIM(tblconns.PRODUCT) && string > _SCREEN.aConnections(ALEN(_SCREEN.aConnections,1),3) = TRIM(tblconns.agency) && string and a new field in tblconns table > _SCREEN.aConnections(ALEN(_SCREEN.aConnections,1),4) = TRIM(tblconns.SERVERNAME) && string > _SCREEN.aConnections(ALEN(_SCREEN.aConnections,1),5) = TRIM(tblconns.DATABASE) && string > _SCREEN.aConnections(ALEN(_SCREEN.aConnections,1),6) = TRIM(tblconns.USERID) && string > _SCREEN.aConnections(ALEN(_SCREEN.aConnections,1),7) = "" && string > _SCREEN.aConnections(ALEN(_SCREEN.aConnections,1),8) = tblconns.engine && numeric > _SCREEN.aConnections(ALEN(_SCREEN.aConnections,1),9) = lnConnNbr && numeric > ? [ * Array results ] > FOR iloop = 1 TO ALEN(_Screen.aConnections,1) > FOR iinsideloop = 1 TO ALEN(_Screen.aConnections,2) > ? _Screen.aConnections(iloop,iinsideloop) > ENDFOR > ENDFOR >ELSE > ? [ ************************************************************* ] > ? [ * Screen array to store connections doesn't exist ] > ? [ ************************************************************* ] >ENDIF >CLOSE ALL >