Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cannot pass by reference
Message
 
To
24/09/2006 11:05:44
Hong Yew
People Quest
Malaysia
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01156776
Message ID:
01156874
Views:
18
>Hi
>
>I need to rewrite the following COM Server program from VB6 to VFP9. The COM client application calls my VFP COM server and pass an object reference. The object has methods that can be called to return various values to my VFP COM server.
>
>My problem is that in my VFP9 COM server, passing by reference doesn't work. Is there something I must specify in my VFP COM server class to allow passing by reference?
>
>The VB6 and translated VFP9 codes below. Please see my comments in my VFP9 code to see where it doesn't work. Your advice much appreciated. Thanks
>
>
>
>VERSION 1.0 CLASS
>BEGIN
> MultiUse = -1 'True
> Persistable = 0 'NotPersistable
> DataBindingBehavior = 0 'vbNone
> DataSourceBehavior = 0 'vbNone
> MTSTransactionMode = 0 'NotAnMTSObject
>END
>Attribute VB_Name = "ExportClass"
>Attribute VB_GlobalNameSpace = False
>Attribute VB_Creatable = True
>Attribute VB_PredeclaredId = False
>Attribute VB_Exposed = True
>
>'***************************************************************
>' This method called by Reader for every page in selection (valid for export)
>' Reader fills fieldsObj (IDispatch) with information from currently exported page
>' fieldsObj has methods
>' Function GetFieldsCount() As Long - return number of fields
>' Sub GetFieldsNames( fieldsNames as Variant ) - fills fieldsNames with names of fields
>' Sub GetFieldsTypes( fieldsTypes As Variant ) - fills fieldTypes with types of fields
>' Sub GetFieldByIndex(ByVal Index as long, OutValue as Variant )
>' Sub GetFieldByName(ByVal Name as String, OutValue as Variant )
>'
>
>Option Explicit
>
>Public Sub ExportMethod(ByVal fieldsObj As Object)
> Dim fieldIndex As Integer
> Dim fieldValue As Variant
> Dim fieldsNames As Variant ' array of page fieldValue names
> Dim fieldsTypes As Variant
> Dim fieldDescr As String
> On Error GoTo err_h
> 'getting page fields names into array of variants for checks or reference
> fieldsObj.GetFieldsNames fieldsNames
> fieldsObj.GetFieldsTypes fieldsTypes
>
> 'iterate fields, determine there types and process
> For fieldIndex = 0 To fieldsObj.GetFieldsCount - 1
> 'get value of fieldValue into fieldValue variable (Variant)
> fieldsObj.GetFieldByIndex fieldIndex, fieldValue
> '........... some codes go here
> '........... some codes go here
> Next fieldIndex
> Exit Sub
>End Sub
>
>My VFP code as follows :
>
>DEFINE CLASS A2FORM AS Session OLEPUBLIC
>cField_Name = ''
>cField_Value = ''
>cField_Type = ''
>
>PROCEDURE Export_Data(toForm AS Object)
>LOCAL lnFields, lni
>PRIVATE lcValue AS Variant
>
>lnFields = toForm.GetFieldsCount() && This call works beautifully!
>IF lnFields >0
> LOCAL ARRAY laFields[lnFields] as Variant
> COMARRAY(toForm,10)
> laFields = 'None'
> toForm.GetFieldsNames(@laFields) && Problem here. laFields cannot be
> && initialised although passed
> && by reference
>
> FOR lni = 1 TO lnFields
> This.cfield_Value = .F.
> lcValue = .F.
> toForm.GetFieldByIndex(lni,@lcValue) && Problem here. lcValue cannot be
> && initialised although passed by reference
> ENDFOR
>ENDIF
>ENDPROC
>
>ENDDEFINE

I am not sure, but because all arrays in VFP are one based I think you should declare them with +1 after you got lnFields.
Try this:
PROCEDURE Export_Data(toForm AS Object)
LOCAL lnFields, lni
PRIVATE lcValue AS Variant

lnFields = toForm.GetFieldsCount()
IF lnFields >0
   LOCAL ARRAY laFields[lnFields+1] as Variant
   COMARRAY(toForm,10)
   laFields = 'None'
   toForm.GetFieldsNames(@laFields)

   FOR lni = 1 TO lnFields+1
      This.cfield_Value = .F.
      lcValue = .F.
      toForm.GetFieldByIndex(lni,@lcValue)
   ENDFOR
ENDIF
ENDPROC
Did you have code of toForm?
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform