With apologies to those who have downloaded what I wrongly claimed was the “final” version a few days ago, I found an error in one of those last minute “improvements” I mentioned. I also took the opportunity to incorporate a couple of refinements that others suggested (thanks CR).
A new version is now available for download and contains the following fixes and changes:
1. Most importantly, I had realised that the CheckReferences() method would give false errors due to an error I introduced without testing – it was one of those: “this is so simple I can’t possibly have made a mistake” things.
Shame on me.
Now might not be the best time to mention that I plan on blogging about my testing framework at some point (I don’t call it a “Unit Testing” framework because it’s actually a bit more than that)
2. The Enabled read/write property is now read-only. To enable or disable an event use the newly added Enable/Disable methods, so where you would previously have written:
someEvent.Enabled := FALSE;
try
// Do something
finally
someEvent.Enabled := TRUE;
end;
now use:
someEvent.Disable;
try
// Do something
finally
someEvent.Enable;
end;
Originally I was aiming to keep the number of methods on a multicast event to a minimum, but I agreed with CR that this way of controlling the enabled state of an event was a bit “funky”.
3. I also agreed with CR that the two IOn_Destroy interfaces were something of a mess (I wouldn’t have gone so far as to call them a “hack” though! lol) and I realised that the problem that the separation into two interfaces had solved no longer applied in that no longer ever implement the interface directly; I always use the TOnDestroy class to add IOn_Destroy support to a class.
Accordingly I have now removed the IOn_Destroy_ interface and extended the IOn_Destroy interface to expose some additional methods of the encapsulated event (since the event itself is now not exposed directly).
Impact Analysis
With the possible exception of the change to the Enabled property, I don’t believe this should affect any code anyone may have written in the short time that the previous version was available.
And I would be very interested to here from anyone that has taken a look and is considering perhaps using the code in their projects, even if it’s just to say “Hi”.
The version containing these changes may be downloaded below.
|
|
download: Multicast - Updated () added: 14/08/2008 clicks: 557 description: Latest version - Bug fix and minor enhancements. |
Meanwhile: Source Code Hosting
Whilst the downloads manager plugin that I’m using with my WordPress blog is very good, I am looking for a more practical solution to source code hosting.
I’ve looked at googlecode and sourceforge and one or two others, and they all seem to use SVN. I personally don’t like SVN. What do other people in my situation do? i.e. they want a source code hosting solution but the tools they use don’t fit with the popular offerings.
Do I just have to grit my teeth and learn to put up with SVN?
Tags: Delphi, download, multicast events, source hosting, SVN
-
Actually now is the best time to mention the testing framework & why it should be used =)
I don’t agree that the Enabled property should be read only. Take for example the standard TDataSet, where you can do either
aDataSet.Open; //Or same as
aDataSet.Active := true;I’ve used SVN for past project (the explorer integration of http://tortoisesvn.tigris.org/ is really nice), but I currently use git (http://git.or.cz/). You could host the project on https://github.com/. There are also plenty of tutorials to get you started: http://www.gitcasts.com/posts/git-on-windows — a basic screencast showing the essentials.
http://excess.org/article/2008/07/ogre-git-tutorial/ — a longer talk about how git works
http://kylecordes.com/2008/04/30/git-windows-go/ — basic instructions how to install gitKeep up the good work,
Ajasja -
This uncertainty whether to provide Enable/Disable methods or just Enabled property or both sounds similar. I usually start also with methods, i.e. Connect/Disconnet, etc. since they sound more natural language.
But, usually at some point there becomes a necessity to, for example, wrap the state or use a simple checkbox or just another Boolean property to control the status – in which case you need to write another wrapper like this:
SetChecked(Checked: Boolean)
if Checked then
Enable
else
Disableand finally at this point I notice that for coding, the Boolean property is much more straight forward, so that should be there at least, to enable simply
SetChecked(Checked: Boolean)
Enabled := CheckedNow you can then decide to also have Enable/Disable, which are just shortcuts to ‘Enabled := True/False’ – just like in the TDataset example Ajasja showed.
BTW: I had missed your later entries to the blog although I subscribed to the RSS feed of Part 1 & 2 – and it was not that straight forward to find the complete series among your blog entries either. I would suggest you add comments to the previous blog entry when you add a new one, to help following.
Anyway, I find your implementation of the events very good. As I mentioned in Part 1 comments, I have a bit similar system, but it requires a “wrapper” object in the event listener part, to handle the “dirty details”. It makes the use a bit more complicated: although you also could not do without the “extra” interface for the destroy notification (which is more neat, anyway).
BTW: In your implementation, is there a simple way to identify the listening objects, if you would like to list them in the sender?
-
It seems my code examples lost their indentation. ‘SetChecked’ is supposed to be a procedure.
-
Yes that sounds quite nice, although I am not sure I understand why you would not put it in the event class? I would think it is easier to notice that there is such, if it is in the class itself?
Anyway, I think it may turn out useful in some occasions!
As for RSS, I am still learning: I noticed that I can subscribe to your complete blog to get notices of new articles. And each article has a separate comment blog, which I need to subscribe as well – now I did not get a notice of your answer here



DelphiFeeds
8 comments
Comments feed for this article
Trackback link: http://www.deltics.co.nz/blog/wp-trackback.php?p=189