Provide an OnChange event for an internal property which is controlled externally?
Posted
by
NGLN
on Programmers
See other posts from Programmers
or by NGLN
Published on 2012-04-14T14:38:36Z
Indexed on
2012/04/14
17:41 UTC
Read the original article
Hit count: 255
delphi
|class-design
For fun and by request I am updating this ImageGrid component, a kind of listbox for images that has a FileNames
property of type TStrings
.
For ease of writing, I have been misusing its FileNames.Objects
property for bitmap storage. But since the TStrings
type suggests that users of the component could or would want to use the Objects
property for custom data, e.g. like TListBox.Items
, I am rewriting the component to store the bitmaps elsewhere and leave FileNames.Objects
untouched for unknown future usage.
Now I am wondering whether to provide an OnChange
event. And if so, whether to fire it when one or more FileNames.Objects
changes.
Trying to answer it myself, I dove in Delphi's own VCL and stumbled on:
TMemo
: has anOnChange
event, but ignoresLines.Objects
TListBox
: has noOnChange
event, but is capable of storingItems.Objects
TStringGrid
: has noOnChange
event, but is capable of storingObjects
,Rows.Objects
,Cols.Objects
So now I am somewhat puzzeled, because I cannot imagine Borland's developers didn't add events for several Objects
properties out of ease. Sure, when a user changes a FileNames.Object
in my component, he knows he does and could implement appropriate interaction himself. But wouldn't it be convenient when the component does automatically?
What would you expect from this component in this regard?
© Programmers or respective owner