tag:blogger.com,1999:blog-8837899541977019574.post1394400648986432835..comments2022-11-16T14:41:56.197+01:00Comments on program begin end. // comments?: Finding yourself in a property bindUnknownnoreply@blogger.comBlogger10125tag:blogger.com,1999:blog-8837899541977019574.post-43418888479885045142011-09-03T11:18:44.330+02:002011-09-03T11:18:44.330+02:00@Francois - I did :)
@Lachlan - I agree. I liked A...@Francois - I did :)<br />@Lachlan - I agree. I liked Andreas' suggestion of using a const. That would really improve the odds where there are multiple references.Lars Fosdalhttps://www.blogger.com/profile/05635001623287214775noreply@blogger.comtag:blogger.com,1999:blog-8837899541977019574.post-32798036379856768712011-09-02T22:17:55.223+02:002011-09-02T22:17:55.223+02:00Still to use XE2 myself but it occurs to me that e...Still to use XE2 myself but it occurs to me that even <br /><br />MyObject.Bind(Src, 'SomeBooleanProperty');<br /><br />makes it easier to spot necessary name changes than a TDBEdit.FieldName property inside the object inspector.LachlanGhttps://www.blogger.com/profile/05666168623106775966noreply@blogger.comtag:blogger.com,1999:blog-8837899541977019574.post-78582620692387517772011-05-19T19:51:31.602+02:002011-05-19T19:51:31.602+02:00You'll want to answer the new survey about the...You'll want to answer the new survey about the next version wanted feature....Françoishttps://www.blogger.com/profile/13066290571047642069noreply@blogger.comtag:blogger.com,1999:blog-8837899541977019574.post-34310433583783899772011-05-12T18:06:00.829+02:002011-05-12T18:06:00.829+02:00Stability issues in the case of I only tested it w...Stability issues in the case of I only tested it with 2 objects and 2 properties of Integer and string and I have no clue how it turns out with tons of objects, other types and more complex life cycles.<br /><br />Look at Sample9 how to use it.Stefan Glienkehttps://www.blogger.com/profile/09320735081289619570noreply@blogger.comtag:blogger.com,1999:blog-8837899541977019574.post-6240626446928337342011-05-12T17:29:33.433+02:002011-05-12T17:29:33.433+02:00@Andreas - Good suggestion for best practice.
@St...@Andreas - Good suggestion for best practice.<br /><br />@Stefan - This looks really interesting. What kind of stability issues are there? Can it be made stable based on the current compiler and RTTI? Also - any usage examples?Lars Fosdalhttps://www.blogger.com/profile/05635001623287214775noreply@blogger.comtag:blogger.com,1999:blog-8837899541977019574.post-67080287885074140582011-05-12T01:46:15.474+02:002011-05-12T01:46:15.474+02:00You might want to look at this:
http://code.googl...You might want to look at this:<br /><br />http://code.google.com/p/delphisorcery/source/browse/trunk/source/Library/System/System.Properties.pas<br /><br />It's far from being stable but to get an idea of what is possible. :)Stefan Glienkehttps://www.blogger.com/profile/09320735081289619570noreply@blogger.comtag:blogger.com,1999:blog-8837899541977019574.post-66801339691335244142011-05-12T00:05:47.095+02:002011-05-12T00:05:47.095+02:00How about this. The string is still there but at a...How about this. The string is still there but at a very easy to maintain location.<br /><br />type<br /> TTestObject = class(TObject)<br /> private<br /> FSomeBoolean: Boolean;<br /> public<br /> property SomeBoolean: Boolean<br /> read FSomeBoolean write FSomeBoolean;<br /> const SomeBooleanProperty = 'SomeBoolean';<br /> end;<br /><br />procedure Main;<br />var<br /> Src: TTestObject;<br /> MyObj: TBoundObject;<br />begin<br /> Src := TTestObject.Create;<br /> MyObj := TBoundObject.Create;<br /> MyObj.Bind(Src, TTestObject.SomeBooleanProperty);<br />end;<br /><br />Unfortunately Delphi's RTTI doesn't contain any class property information. Otherwise the string could be eliminated by using a class property and initializing them in a class constructor.Andreas H.https://www.blogger.com/profile/09493262898327632024noreply@blogger.comtag:blogger.com,1999:blog-8837899541977019574.post-82365858261466458452011-05-11T23:20:51.533+02:002011-05-11T23:20:51.533+02:00That would be a nice syntax, Stefan.
Jolyon, In t...That would be a nice syntax, Stefan.<br /><br />Jolyon, In theory, the unit test would catch the missing string change, but I have yet to see a project of a decent size, developed under time pressure, that has 100% test coverage. Sad, but true.<br /><br />Strong typing implies spotting such errors at compile time, and that is my lament. I get by without property binding - but it would be a great asset.Lars Fosdalhttps://www.blogger.com/profile/05635001623287214775noreply@blogger.comtag:blogger.com,1999:blog-8837899541977019574.post-81374637630335072192011-05-11T22:02:00.536+02:002011-05-11T22:02:00.536+02:00Surely MyObject.Bind(Src, 'SomeBooleanProperty...Surely MyObject.Bind(Src, 'SomeBooleanProperty') CAN be resilient to property renaming, it just depends on the implementation of "Bind".<br /><br />I guess you mean having an earlier failure case, i.e. compilation failure, rather than a unit test failure with a "property does not exist" exception.<br /><br />But if you have that form of resilience (which is better than NO resilience), then isn't what you gain on the swings (less verbose = greater clarity in the code) worth what you trade on the roundabouts (failure during testings vs compilation).<br /><br />I also am assuming that you have unit tests in place. ;)Jolyon Smithhttps://www.blogger.com/profile/12189834837787604468noreply@blogger.comtag:blogger.com,1999:blog-8837899541977019574.post-16009714412731825702011-05-11T20:43:27.649+02:002011-05-11T20:43:27.649+02:00Oh how I wish there was something like:
type
TP...Oh how I wish there was something like:<br /><br />type<br /> TProp<T> = reference to property: T;<br /><br />var<br /> myProp: TProp<Boolean>;<br />begin<br /> myProp := myObject.SomeBooleanPropery;<br />end;Stefan Glienkehttps://www.blogger.com/profile/09320735081289619570noreply@blogger.com