Function/es: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | ## Vision General | |
| 2 | 2 | ||
| 3 | - | ||
| 3 | + | Una **funcion** es una declaracion de una [rutina](</index.php?title=Rutina&action=edit&redlink=1> "Rutina \(page does not exist\)") que puede ser invocada | |
| 4 | 4 | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 5 | + | * desde dentro de una [unidad](</index.php?title=Unidad&action=edit&redlink=1> "Unidad \(page does not exist\)") que la declare | |
| 6 | + | * desde afuera de una unidad si la funcion es publica, | |
| 7 | + | * o desde dentro de un [programa](</index.php?title=Programa&action=edit&redlink=1> "Programa \(page does not exist\)") | |
| 8 | 8 | ||
| 9 | - | ||
| 9 | + | La rutina devuelve un valor como parte de su definicion. Una rutina que no devuelve un valor como parte de su definicion es un _[procedure](</index.php?title=Procedimiento&action=edit&redlink=1> "Procedimiento \(page does not exist\)")_. | |
| 10 | 10 | ||
| 11 | - | ||
| 11 | + | Una funcion que es parte de un objeto es conocida como una [propiedad](</index.php?title=Propiedad&action=edit&redlink=1> "Propiedad \(page does not exist\)") y puede ser asignada/devuelta como valor (si no puedes asignarle un valor, esta deberia ser un [metodo](</index.php?title=Metodo&action=edit&redlink=1> "Metodo \(page does not exist\)")) | |
| 12 | 12 | ||
| 13 | 13 | ## Parametros de Funcion | |
| 14 | 14 | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 15 | + | * Llamada por valor | |
| 16 | + | * [Parametros variables](</index.php?title=Parametros_variables&action=edit&redlink=1> "Parametros variables \(page does not exist\)") (llamada por referencia) | |
| 17 | + | * Parametro de salida (out) | |
| 18 | + | * Parametro constante (const) | |
| 19 | + | * [Parametros por omision](</index.php?title=Parametros_por_omision&action=edit&redlink=1> "Parametros por omision \(page does not exist\)") | |
| 20 | + | * Arreglos abiertos de parametros | |
| 21 | + | * Arreglos de constantes (const) | |
| 22 | 22 | ||
| 23 | 23 | ## Ejemplos | |
| 24 | 24 | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 25 | + | Suma de dos Enteros [enteros](</index.php?title=Enteros&action=edit&redlink=1> "Enteros \(page does not exist\)") ejemplo: | |
| 40 | 26 | ``` | |
| 27 | + | function suma(c1, c2 : integer) : integer; | |
| 28 | + | begin | |
| 29 | + | suma := c1 + c2; //o use result := in Object Pascal/Delphi mode | |
| 30 | + | end; | |
| 31 | + | ||
| 32 | + | var | |
| 33 | + | total: integer; | |
| 34 | + | ||
| 35 | + | begin | |
| 36 | + | total := suma(4, 5); | |
| 37 | + | writeln (total); // el resultado es 9 | |
| 38 | + | end. | |
| 39 | + | ``` | |
| 41 | 40 | ||
| 42 | 41 | --- | |
| 43 | - | ||
| 42 | + | *From the Free Pascal wiki, page "Function/es", as the Internet Archive kept it on 2022-08-16. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
