Schnellstart
In weniger als 5 Minuten haben Sie Ihre erste .NET-Klasse, die aus VFP lauft.
Schritt 1: FoxBridge initialisieren
loBridge = NEWOBJECT("FoxBridge", "FoxBridge.prg")
? loBridge.Ping() && "Pong" confirma que la DLL esta cargada Schritt 2: Ihr erstes .NET-Objekt erstellen
System.Text.StringBuilder ist eine .NET-Klasse, die Zeichenketten effizient erstellt. Es ist das 'Hallo Welt' von FoxBridge.
* Crear un StringBuilder con texto inicial
loSB = loBridge.Create("System.Text.StringBuilder", "Hola ")
* Llamar metodos encadenados
loSB.Append("mundo ")
loSB.Append("desde .NET!")
* Convertir a string VFP
lcResultado = loSB.ToString()
? lcResultado && "Hola mundo desde .NET!"
* Ver cuantos caracteres tiene
? loSB.Length && 22
* Liberar
loSB = .NULL. Schritt 3: Mit generischen Sammlungen arbeiten
FoxBridge ubersetzt List<T> und Dictionary<K,V> in VFP-Proxys. Die Indizierung ist 1-basiert (wie VFP).
* Crear una List<String>
loLista = loBridge.Create("List<String>")
* Agregar elementos
loLista.Add("Visual FoxPro")
loLista.Add("C#")
loLista.Add("F#")
? "Total:", loLista.Count() && 3
? "Primero:", loLista.Item(1) && "Visual FoxPro" (base-1)
* Recorrer la lista
For i = 1 to loLista.Count()
? loLista.Item(i)
Next
* Eliminar un elemento
loLista.Remove("F#")
? "Despues de Remove:", loLista.Count() && 2
loLista = .NULL. Schritt 4: Statische Methoden aufrufen
Viele .NET-Klassen haben statische Member (keine Instanziierung notig). Wir verwenden loBridge.Static() um auf sie zuzugreifen.
* System.Math es una clase estatica (no se puede instanciar)
loMath = loBridge.Static("System.Math")
? loMath.Abs(-42) && 42
? loMath.Sqrt(144) && 12
? loMath.Max(10, 20) && 20
? loMath.PI && 3.14159...
* System.IO.File: leer y escribir archivos
loFile = loBridge.Static("System.IO.File")
loFile.WriteAllText("C:prueba.txt", "Hola desde FoxBridge")
? loFile.Exists("C:prueba.txt") && .T.
? loFile.ReadAllText("C:prueba.txt")
loMath = .NULL.
loFile = .NULL. Schritt 5: Eigene DLL laden
FoxBridge kann jede selbst kompilierte .NET-DLL laden.
* Cargar tu DLL compilada en .NET
llOk = loBridge.LoadAssembly("C:MiAppinMiLogica.dll")
IF llOk
* Instanciar una clase de tu DLL
loObj = loBridge.Create("MiEmpresa.MiLogica.Calculadora", 0.16)
lnTotal = loObj.CalcularConIVA(1000.00)
? "Total con IVA:", lnTotal
loObj = .NULL.
ELSE
? "Error:", loBridge.GetLastError()
ENDIF Goldene Regel Geben Sie FoxBridge-Objekte immer mit = .NULL. frei, wenn Sie sie nicht mehr benotigen. Dadurch wird Speicher im .NET-Heap freigegeben.
Weiter: Beispiele ->