visual-foxpro
VFP Interop con .NET
Ricerca…
introduzione
Questo argomento coprirà l'intervallo tra VFP e .NET.
Utilizzo di wwDotNetBridge per eseguire il codice .NET
Con l'aiuto di wwDotNetBridge di West Wind , puoi facilmente accedere al codice .NET all'interno di un programma VFP.
Il white paper ha tutti i dettagli, ma questo breve esempio illustrerà i passaggi di base per eseguire un metodo in un assembly .NET.
Si noti che wwDotNetBridge può accedere direttamente a proprietà semplici come stringhe, int, ecc. Per accedere a strutture più complesse come gli elenchi, è necessario prima utilizzare la funzione wwDotNetBridge CreateArray per convertire la struttura .NET in un array COM VFP (come mostrato nella figura in basso di questo esempio).
*!* Load WestWind .NET wrapper library (wwdotnetbridge.prg assumed to be in the search path)
IF (!wwDotNetBridge())
RETURN .F.
ENDIF
lowwDotNetBridge = CREATEOBJECT("wwDotNetBridge","V4")
*!* Load .NET Assembly (include full or relative path if necessary)
IF !lowwDotNetBridge.LoadAssembly("SomeDotNetAssembly.dll")
lcAssemblyLoadError = "LoadAssembly error: " + lowwDotNetBridge.cErrorMsg
=MESSAGEBOX(lcAssemblyLoadError, MB_ICONSTOP, "Error")
RETURN .F.
ENDIF
*!* Parameters to pass to class constructor
*!* You can pass up to 5 paramenters to the constructor
lcParameter1 = "StringParameter1"
lcParameter2 = "StringParameter2"
lnParameter3 = 3
lcParameter4 = .NULL.
*!* Get an instance of the assembly class
loAssemblyReference = lowwDotNetBridge.CreateInstance("MyDotNetProject.MyDotNetClass", ;
lcParameter1, lcParameter2, lnParameter3, lcParameter4)
IF lowwDotNetBridge.lError
lcAssemblyLoadError = "An error occurred loading the class: " + lowwDotNetBridge.cErrorMsg
RETURN .F.
ENDIF
*!* Usage Example
*!* This example runs a method that return a boolean
*!* and populates a List<string> (SomeStringList).
*!*
*!* The assembly has a public property named "LastErrorMessage"
*!* with details about any handled exceptions/problems.
IF (!loAssemblyReference.SomePublicMethod())
msg = "There was a problem executing the method:" + CRLF + ;
loAssemblyReference.LastErrorMessage
=MESSAGEBOX(msg, MB_ICONSTOP, "Error")
RETURN .F.
ENDIF
*!* At this point the string list (SomeStringList) should be populated
*!* wwDotNetBridge can convert that list to a VFP COM array (0-based)
laVFPArrayOfStrings = lowwDotNetBridge.CreateArray()
laVFPArrayOfStrings.FromEnumerable(loAssemblyReference.SomeStringList)
FOR x = 0 TO laVFPArrayOfStrings.Count-1
? laVFPArrayOfStrings.Item(x)
ENDFOR
Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow