firemonkey - Delphi - Getting property values with GetPropValue() -
i'm using delphi's getpropvalue()
function values of properties of objects of type tcontrol
. works correctly when simple property values such value
, opacity
, etc, i'm using firemonkey there extended properties, such rotationcenter
, has rotationcenter.x
, rotationcenter.y
, or properties of text within textsettings
, in these properties sub-types can not values.
in example values correctly:
if ispublishedprop (component_cc, 'value') editvalue.text: = getpropvalue (component_cc, 'value', true);
where component_cc:tcontrol
; , created dynamically, can type of firemonkey component (so far okay, works).
when need use form below, not work.
if ispublishedprop (component_cc, 'rotationcenter.x') editrotationcenterx.text: = getpropvalue (cc_component, 'rotationcenter.x', true);
does know way these properties extended function?
first, cc_component's rotationcenter
property instance of tposition
class decends tpersistent
.
second, cannot use dotted notation when calling ispublishedprop
.
you can use getobjectprop
first retrieve internal tposition
instance , access x
property there:
(assume simple fmx application 1 form contains tbutton
called button1
, tedit
called editrotationcenterx
.)
procedure tform1.button1click(sender: tobject); var cc_component : tcomponent; cc_component_rotationcenter : tposition; begin cc_component := button1; if ispublishedprop(cc_component, 'rotationcenter') begin cc_component_rotationcenter := tposition(getobjectprop(cc_component, 'rotationcenter')); editrotationcenterx.text := cc_component_rotationcenter.x.tostring; end end;
update, property of type set:
for set type property, need retrieve ordinal value using getordprop
. array of bits represent elements included in current value. then, test if appropriate bit set. method prefer.
alternatively can use getsetprop
return text representation of elements in set's current value. example, if set's value [tcorner.bottonleft, tcorner.topright]
string value "topright,bottonleft". check see if name of target element appears anywhere in returned string. method susceptible failure if delphi rtl or fmx libraries ever changed in future.
(this example adds trectangle
shape called rectangle1
, tcheckbox
called cbcornerbottonright
simple fmx app above:)
procedure tform1.button1click(sender: tobject); var cc_component : tcomponent; cc_component_corners : nativeint; cc_component_cornersasstring : string; begin cc_component := rectangle1; if ispublishedprop(cc_component, 'corners') begin // using method make code less sensitive // changes in ordinal values of set's members or // changes names of enumeration elements. // cc_component_corners := getordprop(cc_component,'corners'); cbcornerbottonright.ischecked := ((1 shl ord(tcorner.bottomright)) , cc_component_corners) <> 0; // approach may break if names of elements of // tcorner enumeration ever changed. (btw, have // been in past: "cvtopleft", "cvtopright", "cvbottomleft", // , "cvbottomright" deprecated) // cc_component_cornersasstring := getsetprop(cc_component,'corners'); cbcornerbottonright.ischecked := cc_component_cornersasstring.indexof('bottomright') >= 0; end; end;
Comments
Post a Comment