indexers_indexed_property
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| indexers_indexed_property [2018/09/06 19:25] – created wolfgangriedmann | indexers_indexed_property [2018/09/11 08:37] (current) – wolfgangriedmann | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Indexers and indexed properties ====== | ====== Indexers and indexed properties ====== | ||
| + | Indexers are a new concept for xBase developers. They permit to access the properties of an object like an array. Please see this sample class: | ||
| + | <code visualfoxpro> | ||
| + | protect oValues as List< | ||
| + | |||
| + | constructor() | ||
| + | |||
| + | oValues := List< | ||
| + | |||
| + | return | ||
| + | |||
| + | property self[ nIndex as int ] as string | ||
| + | get | ||
| + | if oValues: | ||
| + | return oValues[nIndex-1] | ||
| + | else | ||
| + | return "" | ||
| + | endif | ||
| + | end get | ||
| + | set | ||
| + | while oValues: | ||
| + | oValues: | ||
| + | end | ||
| + | oValues[nIndex-1] : | ||
| + | end set | ||
| + | end property | ||
| + | |||
| + | end class</ | ||
| + | This class can be used like this: | ||
| + | <code visualfoxpro> | ||
| + | local oTest as IndexerTest | ||
| + | local nI as int | ||
| + | |||
| + | oTest := IndexerTest{} | ||
| + | oTest[1] := " | ||
| + | oTest[2] := " | ||
| + | oTest[3] := " | ||
| + | oTest[4]:= " | ||
| + | |||
| + | for nI := 1 upto 5 | ||
| + | Console.WriteLine( i" | ||
| + | next | ||
| + | |||
| + | return</ | ||
| + | |||
| + | Classes with indexed properties can also be used like classes with dynamic arrays. Please see this sample: | ||
| + | <code visualfoxpro> | ||
| + | protect _oValues as Dictionary< | ||
| + | |||
| + | constructor() | ||
| + | _oValues : | ||
| + | return | ||
| + | |||
| + | property self[cName as string] as string | ||
| + | get | ||
| + | local cValue as string | ||
| + | if _oValues: | ||
| + | cValue := "< not assigned >" | ||
| + | endif | ||
| + | return cValue | ||
| + | end get | ||
| + | set | ||
| + | if _oValues: | ||
| + | _oValues[cName] : | ||
| + | else | ||
| + | _oValues: | ||
| + | endif | ||
| + | end set | ||
| + | end property | ||
| + | |||
| + | end class</ | ||
| + | To be used like this: | ||
| + | <code visualfoxpro> | ||
| + | oObject[" | ||
| + | oObject[" | ||
| + | System.Console.WriteLine( " | ||
| + | System.Console.WriteLine( " | ||
| + | System.Console.WriteLine( " | ||
| + | |||
| + | Please see also this Microsoft article: [[https:// | ||
| + | |||
| + | And there is also a forum thread about this: | ||
| Please see https:// | Please see https:// | ||
indexers_indexed_property.1536261925.txt.gz · Last modified: 2018/09/06 19:25 by wolfgangriedmann