Constructor/es: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | - | ||
| 1 | + | La palabra reservada **constructor** es parte de la programación orientada a objetos y se utiliza para inicializar una clase. Las clases simples que no requieren inicialización, no necesitan un constructor. Una clase auto-escrita que no tiene ningún constructor puede heredar el constructor de su clase principal (si tiene un constructor). | |
| 4 | 2 | ||
| 5 | - | ||
| 3 | + | Ejemplo: | |
| 4 | + | ``` | |
| 6 | 5 | // Definición de la calse | |
| 7 | - | ||
| 8 | - | ||
| 9 | - | ||
| 10 | - | ||
| 11 | - | ||
| 12 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 6 | + | type | |
| 7 | + | TClase = class | |
| 8 | + | end; | |
| 9 | + | ||
| 10 | + | var | |
| 11 | + | unaClase: TClase; // Declarar una variable del tipo TClase | |
| 12 | + | ||
| 13 | + | begin | |
| 14 | + | ... | |
| 15 | + | // Crear la clase | |
| 16 | + | unaClase := TClase.Create; // Create invoca al constructor heredado de la clase primaria | |
| 17 | + | ... | |
| 18 | + | end; | |
| 20 | 19 | ``` | |
| 21 | 20 | ||
| 22 | 21 | --- | |
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 22 | + | *From the Free Pascal wiki, page "Constructor/es", as the Internet Archive kept it on 2023-03-20. 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).* |
