0
votes

The problem is related to the usage of VFP COM server from Visual basic 6.0 (SP 6).

Code (relevant)

Private moVFPServer As f_vfpsvr.VFPServer

In the Sub:

Dim oRec As f_vfpsvr.VFPRecord 
Set oRec = moVFPServer.NewRecord("LoanMstr")    
With oRec    
  .SetField "ssn", sSSN    
  .SetField "awdyr", sAwardYear    
  .SetField "tran_date", Format(Now, "mm/dd/yyyy")    
  .Commit    
End With

Method "NewRecord" from moVFPServer returns an object which represents a new, empty record in the VFP table "LoanMstr".

Code follows to populate properties/fields and save data.

All this works if VFP COM server is built using VFP 8.0 and does not work when built using VFP 9.0.

Specifically, VB application errors out at the line of code:

Set oRec = moVFPServer.NewRecord("StdMstr")

COM server throws exception: automation error -2147417851.

This is happening on the same machine.

1
Does the COM object work when called from VFP 9?Tamar E. Granor
-2147417851 = 0x80010105 = "The server threw an exception". Your foxpro code crashed.Hans Passant
Tamar, I checked and it does not work in VFP development environment on VFP 8 or VFP 9.Paul
Hans, exactly it crashed. The point is that code is executed by methods in COM server and it crashes exactly at the time when object is returned to the calling VB program.Paul
BTW, method NewRecord in VFPServer calls another method which in turn instantiates object based on class VFPRecord located in the same DLL. If anybody would like to know how exactly method NewRecord works I will email the program containing classes. It is quite short and clean.Paul

1 Answers

1
votes

VFP built COM objects can behave a little oddly at times, especially when it comes to trickling errors back up the stack.

But it seems very strange that this manifests only when built in VFP9. I believe there WERE some breaking changes in database stuff between 8 and 9 some possibly you've hit one of them?

Do you have an ERROR function in the VFP code? If not, try setting some error properties in that and interrogating them in VB when you get the error?

Ie, we have something like

FUNCTION ERROR(nError, cMethod, nLine)
    THIS.cErrDesc = "Error Number: " + TRANSFORM(nError) + CRLF + "Message: " + MESSAGE() + CRLF  + "Method: " + cMethod + CRLF  + "Line #: " + TRANSFORM(nLine)

    COMRETURNERROR(cMethod, THIS.cErrDesc)

ENDFUNC