Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get the underlying raw Variant value of a Delphi 6 indexed property that accesses that Variant?
    primarykey
    data
    text
    <p>I have a Delphi 6 class object that contains an array of 30 Variants, each of which is exposed via a different indexed property. For example:</p> <pre><code>property responseCode: integer Index 7 read getIndexedProperty_integer write setIndexedProperty_integer; </code></pre> <p>I did this to make using the array of Variants easier (helps the IDE's auto-complete) and to provide type safety. It works fine but now I have a wrinkle. The array of Variants are initialized to NULL when the class that wraps it is constructed, so I can tell if a particular variant has ever been instantiated with a value. A consequence of this is if only some of the Variants are instantiated (given valid values), any attempt to access a property that currently represents a NULL Variant will cause a Variant conversion error when Delphi tries to convert the variant to the type declared by the indexed property.</p> <p>I would much rather not declare an "isValid" property for each indexed property. I was wondering if there was a way to use the TypeInfo library to get the raw value of the underlying Variant without having to access the indexed property directly and thus triggering the conversion Exception. Then I could write code like (using the example property above):</p> <pre><code>isValidProperty(responseCode); </code></pre> <p>and that function would return TRUE if the Variant underlying the responseCode property is not NULL and FALSE if it is.</p> <p>I know I can walk the PPropList property list for the class and access the properties by name, but then I would have to use code like:</p> <pre><code>isValidProperty('responseCode'); </code></pre> <p>and pass the property name in string form instead of passing in the property directly like the first isValidProperty() above. Is there a way to do this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload