Quick start
In under 5 minutes you will have your first .NET class running from VFP.
Step 1: Initialize FoxBridge
loBridge = NEWOBJECT("FoxBridge", "FoxBridge.prg")
? loBridge.Ping() && "Pong" confirma que la DLL esta cargada Step 2: Create your first .NET object
System.Text.StringBuilder is a .NET class that builds strings efficiently. It is the 'Hello World' of 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. Step 3: Work with generic collections
FoxBridge translates List<T> and Dictionary<K,V> to VFP proxies. Indexing is 1-based (like 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. Step 4: Call static methods
Many .NET classes have static members (no instantiation needed). We use loBridge.Static() to access them.
* 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. Step 5: Load your own DLL
FoxBridge can load any .NET DLL you have compiled yourself.
* 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 Golden rule Always release FoxBridge objects with = .NULL. when you no longer need them. This frees memory in the .NET heap.
Next: Examples ->