|
|
|
|
- Declarar una estructura
- Utilizar un array de estructuras
¿Cómo manipular un array de estructuras?
Un array de estructuras es una variable de tipo Array. Cada elemento del array es de tipo Structure. Por ejemplo, se puede utilizar un array de estructuras: - para almacenar un array de líneas de pedido.
- para almacenar una lista de contactos.
Para declarar una variable de tipo Array de estructuras, es necesario - Declarar la estructura.
- Declarar un Array de la estructura previamente declarada.
La sintaxis es la siguiente MyStructure is Structure Member1 is <type of variable> Member2 is <type of variable> ... END
MyArray is array of MyStructure Por ejemplo: stOrderLine is Structure LineNum is int ProductRef is string Qty is int UnitPrice is currency END
arrOrdLines is array of stOrderLine
Utilizar un array de estructuras Para utilizar un array de estructuras, es necesario: - Declarar un Array de la estructura previamente declarada.
- Declarar una variable simple que represente un elemento del tipo de la estructura.
- Inicializar los miembros incluidos en esta variable simple.
- Agregar la variable simple al array.
Por ejemplo: stOrderLine is Structure LineNum is int ProductRef is string Qty is int UnitPrice is currency END AnOrdLine is stOrderLine arrOrdLines is array of stOrderLine // Fill the array AnOrdLine.LineNum = 1 AnOrdLine.ProductRef = "Ref001" AnOrdLine.Qty = 5 AnOrdLine.UnitPrice = 100.0 ArrayAdd(arrOrdLines, AnOrdLine) AnOrdLine.LineNum = 2 AnOrdLine.ProductRef = "Ref005" AnOrdLine.Qty = 1 AnOrdLine.UnitPrice = 2100.0 ArrayAdd(arrOrdLines, AnOrdLine) AnOrdLine.LineNum = 3 AnOrdLine.ProductRef = "Ref019" AnOrdLine.Qty = 16 AnOrdLine.UnitPrice = 22.0 ArrayAdd(arrOrdLines, AnOrdLine) // Read the array again: method 1 FOR EACH ELEMENT OrdLine OF arrOrdLines Trace(OrdLine.ProductRef, OrdLine.Qty, OrdLine.Qty * OrdLine.UnitPrice) END // Read the array again: method 2 FOR nSub =1 TO arrOrdLines.Count Trace(OrdLine[nSub].ProductRef, OrdLine[nSub].Qty, OrdLine[nSub].Qty * OrdLine[nSub].UnitPrice) END
Observaciones Las estructuras y los arrays de estructuras se pueden declarar: - en el código del proyecto (estructura global a todo el proyecto).
- en el código de una ventana o página (estructura global a la ventana o página).
- en cualquier proceso o evento (estructura local al proceso o evento).
Esta página también está disponible para…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|