Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Working with Safe Arrays?
Message
De
03/08/2004 11:07:43
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Titre:
Working with Safe Arrays?
Divers
Thread ID:
00930360
Message ID:
00930360
Vues:
61
According to the VFP 8 help on DEFINE CLASS I should be able to specify an array as type String instead of the deault Variant. Supposedly this is achieved by using the AS clause in the paramter list which I have tried to no avail. In the below example, the SAS object should be return a list of library references as string values in an array. Apparently the arrays must all be of type string and be what is called a Safe Array. Has anyone had any luck using Safe Arrays in VFP 8?

Here is what I have tried without success in many different combinations:
DEFINE CLASS test as Custom OLEPUBLIC
 oWM = NULL
 oSAS = NULL
	
 PROCEDURE AddRow(tcDesc, tcValue)
  INSERT INTO test_it (when, desc, value) values(DATETIME(),;
             TRANSFORM(tcDesc), TRANSFORM(tcValue))
 ENDPROC

 PROCEDURE Main()
  IF NOT used('test_it')
   CREATE TABLE test_it (pk i autoinc, when t, desc c(20), value c(100))
  ENDIF
		
  This.AddRow('Start Main', 'Testing')
  This.oWM = CREATEOBJECT('SASWorkspaceManager.WorkspaceManager')
  oServerDef = CREATEOBJECT('SASWorkspaceManager.ServerDef')
  oServerDef.Protocol = 2 && PROTOCOLBRIDGE
  oServerDef.MachineDNSName = 'machinename'
  oServerDef.Port = 12010

  errorstring = ''	
  This.oSAS = This.oWM.Workspaces.CreateWorkspaceByServer("UnixName",;
		1, oServerDef, "username", "password", errorString)
			
  oLibRef = This.oSAS.DataService.AssignLibref("unixlib","","/m01/usx714a","")
  This.AddRow('olibref.name', olibref.name)

  *-- all above works fine		
  DIMENSION lax[2] AS string
  lax = 'a' && force to a string
  This.CallSAS( @lax )
  FOR lni = 1 TO ALEN( lax,1 )
    This.AddRow('lax['+ALLTRIM(STR(lni)) + ']', lax[lni])
  NEXT

  PROCEDURE CallSAS( ax[] AS String @)
   TRY 
    *-- tried ComArray as 10 and 11
    COMARRAY( This.oSAS.DataService, 10 )
    this.oSAS.DataService.ListLibrefs( @ax )
    FOR lni = 1 TO ALEN( ax,1 )
     This.AddRow('ax['+ALLTRIM(STR(lni)) + ']', ax[lni])
   NEXT
   CATCH
   FINALLY
    *-- shut down SAS
    this.oWM.WorkSpaces.RemoveWorkSpace( This.oSAS)
    This.oSAS.Close()
  ENDTRY
  RETURN ax
 ENDPROC
ENDDEFINE
here is an extract from the help file related to using Safe Arrays:
cArrayName[] [AS Type ][@][AS Type] 
Specifies the name of the array used in the creation of a type library using the
first AS Type clause. Using the cArrayName[] [AS Type][@] clause, you can specify 
strong typing for arrays so they can be correctly written as safe arrays to a type 
library. For example: 
DEFINE CLASS foo AS Session OLEPUBLIC
    PROCEDURE GetWidgets1(aWidgets[])
    ENDPROC
    PROCEDURE GetWidgets2(aWidgets[] AS Integer)
    ENDPROC
    PROCEDURE GetWidgets3(aWidgets[] AS Integer @)
    ENDPROC
    PROCEDURE GetRS(oRS[] AS ADODB.RECORDSET @)
    ENDPROC
ENDDEFINE
Note Strong typing for arrays is used primarily for type library creation and is 
not enforced at run time.

The type that you specify must be a valid COM data type (see the previous table). 
The type can also be a reference to a COM CoClass ProgID such as ADODB.Recordset. 
If you specify an argument for the first AS Type clause, Visual FoxPro creates a 
SAFEARRAY with the specified type. If you do not specify an argument for the first 
AS Type clause, Visual FoxPro creates a SAFEARRAY of Variant data types. If the 
type specified is invalid, Visual FoxPro defaults to using the Variant data type. 
Note When specifying an array, you must use square brackets ([]); DEFINE CLASS does 
not recognize parentheses (()) notation.

A safe array is a one or multidimensional array of a single data type, which can 
be of type VARIANT, allowing you to create arrays of mixed types. The safe array 
stores its lower bound, which does not have to be zero, and its size. Safe arrays 
allow locking and unlocking so you can be sure that the pointer you receive to the 
data is valid. 
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform