Holger's Thoughts on Delphi

Saturday, December 31, 2005

ECO: Categories And Recursive OCL

...and no custom OCL - this time. It's just recursive this time.

"Ouch, recursive, don't want to hear it..." - Well, give it a shot... you'll like it, I am sure of it.

Categories pretty much appeared in any model given as an example how to build certain things using ECO. There was a class "Category" mostly all the time. But none of the examples really got into the details how to build a hierarchy of categories. Thus, you could use the "Category" class for navigation in ASP.NET-projects e.g.

Let me give you an example: We want to list all the blogs of Borland employees. So my root category is "Borland". I distinguish in my example between "R&D" and "DevRel". So my second level consists of those two "nodes".

If you clicked on "Borland" and "DevRel" you get something like "> Borland > DevRel" in your navigation, so you know where you are. I heard the term "breadcrumbs" for that kind of caption.

As I am a very lazy programmer I want to let ECO handle most of the maintenance. I just want to specify the names and want to name a certain category a sub-category of another one (of course, with ECO you can also add children to a parent-node, i.e. vice-versa).



Summing up the model: The only non-derived attribute is "name", which identifies the category. All other attributes are read-only and maintained by ECO. ECO can determine the level of a category in the "category tree" and can also return the "full name" (aka breadcrumb) to you. I achieve this using recursive OCL.

Let's have a look at the associations of Category first. There is only one association and it is directed at Category itself. Yes, it is possible, even if it looks funny at first. I changed the multiplicity, so that each Category can have multiple offspring (role: Children), but only one parent (role: Parent). You can change that of course, but this example is already complicated enough if you never handled recursion and ECO. This little trick allows us to access the name of the parent category by specifying "Parent.name".

So I derived the level of a category like this:


And the breadcrumb-String is calculated using these lines of native OCL:



  • Level:To understand it, start with one category. Its level is 0. Now think of one category with one sub category. Nothing changes for the "root", but the first child category has the level 1, as Parent.level + 1 = 0 + 1 = 0. That's it. (Call my explanation a poor-man's-proof by induction... ;-) And yes, I know it is not complete or formally correct.)

  • Full name:It works the same way as level, but instead of adding 1 to the level on our way up the tree, we add the name of the current category to the full name of the parent node.


Be aware that you must have a starting condition/point. In this case it is that a category does not have any parent and thus is on the root level. Otherwise, you end up with an endless loop.

As always, I created a tiny, simple demo application. I add the following objects to my Eco Space by code:


procedure TWinForm.TWinForm_Load(sender: System.Object;
e: System.EventArgs);

var
cmain: Category;
csub : Category;
csubsub: Category;

begin
cmain := Category.Create(EcoSpace);
cmain.name := 'Borland';

csub := Category.Create( EcoSpace );
csub.name := 'R&D';
csub.Parent := cmain;

csubsub := Category.Create(EcoSpace );
csubsub.name := 'Jonas Högström';
csubsub.Parent := csub;

csubsub := Category.Create(EcoSpace );
csubsub.name := 'Jesper Högström';
csubsub.Parent := csub;

csub := Category.Create( EcoSpace );
csub.name := 'DevRel';
csub.Parent := cmain;

csubsub := Category.Create(EcoSpace );
csubsub.name := 'John Kaster';
csubsub.Parent := csub;
end;

Finally, I built a Winform with a simple grid that shows all the properties of the instances of the class "Category":



One can easily see the possibilities this opens for web site development as you can build your navigation this way. Furthermore, you can include the "Category" class in lots of models. Take note of the fact that this approach is completely "pluggable" into any other model without using any functionality. You also never have to reinvent the wheel again for objects that have these characteristics.

Have a Happy New Year everybody!

Layout changes

It's been pushed away by me long enough. I had to change from a coloured background to a white background, because of all the screenshots I post. It just did not look nice, with the white borders around the images instead of the orange background.

I hope you like it as I think the text is also more readable, because of a clearer, black font on a white background.

Tuesday, December 27, 2005

IntraWeb 8.0 released

As I hinted in an earlier post, the Delphi Community gets a delayed Christmas Present. IntraWeb 8.0 has been released! Read all about it here on Olaf's Blog.

Monday, December 26, 2005

ECO: Custom Operations, Investments and Net Present Value

Yes, no typo. ECO in the same context as math and finances. If you have worked with Excel, you might have seen the financial formulae. ECO is missing those.

So I extended ECO III a little bit and can check if an investment should be made or declined without a single line of code. My OCL extentions also give you the ability to calculate the optimal interest rate your bank has to offer to you, so that you can proceed with your investment (change: called the internal rate of return, thanks Olaf for the translation assistance). Everything is based on the theory of the "net present value" (Wikipedia Germany has a detailed article on that e.g.).

Christmas triggers funny things sometimes, for me it was going back 4 years and reliving the worst exam I ever had to take: Monetary Policy. That's all I am going to say about that. At least I can implement the stuff as an ECO Custom OCL Operation, eh? :-)

I used my other extentions of the OCL language as well. Basically, I am building a huge library with custom operations. Right now, there is no real structure, which categories I am going to cover in the library. I simply implemented what came to mind and made sense to me.

Back to the investment application.

Let me show you the simple model. This model could be one building block of a huge financial application. Yes, it's only for demo purposes and it might be enhanced a lot. But it shows the power you have, when building custom operations in ECO. Remember: not a single line of code for the Winforms application that lets the user plan his or her investments needs to be written!




  • we have one class for investments
  • another for payments for the investments
  • the idea is to create one "Payment" for every period that is to be considered in the calculation
  • the number of payments determines the total number of periods, we can consider this the asset depreciation range e.g.
  • currencies are not modelled
  • a "Payment" simply has an amount. Think of it as a yearly payment you get because of the initital investment to get started
  • an investment has a name, an inital amount that has to be paid for the investment, an interest rate and "sellPrice" that stands for the money that will be earned for the investment being sold after the usage


I will continue by showing you the main form of the application. Remember these things: If the net present value is positive, go ahead. If negative, continue planning. The optimal interest rate can be calculated if you solve the equation for "Net Present Value equals 0".



What you see is one investment for a new computer. I bought a computer for 2000 bucks, which I sold after 4 years for 1000 bucks and my bank's interest rate is 8% over that period of time. Can I realize it? Yes, as the "net present value" is positive. Hmmm. What would be optimal? An interest rate of 0,098051, because the NPV is almost 0 at that interest rate. A note: I used a regula falsi approximation to solve the equation.

If you're not amazed by this... I sure am. Just think of the possibilities. I can easily build different scenarios with this application, compare them and consider all the consequences. Again: no code.

So, how does the OCL look? Not very complex. Here's a screenshot that shows how to calculate the optimal interest rate:



What do you think about custom operations now?

Furthermore, if anybody is interested in these extentions, let me know by commenting here. Suggestions are also welcome, of course.

Sunday, December 25, 2005

ECO: Custom Fun

Design-time and run-time: Both working fine. This is the first time, I've tried to build my own operations. As you can see in the following screenshot, my additional OCL methods are getting more complex by the minute. At first I used no parameters for the methods "getAgeInYears" and "getAgeInDays". Both methods calculate the current (in relation to today) age for a person's birthday.

However, the method "getDiffToDate" (which I might have to rename as the name is not that good...) has two additional parameters. If you e.g. want to get the difference of two dates in days you'd write:
  • myDate.getDiffToDate( otherDate, 'd' )

The 'd' specifies days. You could also use 'm' or 'y'. I think it is pretty obvious which result that would yield. 'm' will return the difference in months and 'y' will do the same in number of years.

Now, the possibilities with ECO are really infinite. Just consider that you can build customized OCL operations for your customers. It really improves the structure of your code.



(Thanks to my friend Jim for his help to improve grammar, structure and spelling in my posts!)

ECO: Custom OCL Operations

Daniel Polistchuck posted some really interesting basics about writing custom OCL operations for ECO III. This got me started writing some really basic Date/Time-stuff. It is really easy to do, especially when you have a nice code template handy ;-)


  • create a new C# class file
  • select all and press Del
  • type "newoclop" and press TAB
  • fill in the gaps


Download

Right now I am writing a template that modifies your ECO Space, so that you can install these operations during design-time and run-time with ease.

Stay tuned.

Friday, December 23, 2005

StarTeam: Getting started...

I want to save everybody some time, who wants to install StarTeam for the first time. I could not find one thing in the manual and I had to google the newsgroups in order to find an answer.

Let's say, you created a new configuration inside your server, everything is set up and you start the server for the very first time.

Well, you need to add users, so they can log in.

Ok, so there is Accounts / User Manager. Click it... User name? Password? Did I set up any users? Of course not, but there is something like "root" in StarTeam as well.

Use
  • Username: Administrator
  • Password: Administrator


and you will be logged in. I spent so much time browsing the manuals for this, but I simply could not find it.

Thus, to safe you some time I thought this was a nice post.

Merry Christmas!

Yes, it's that time of the year already!

Merry Christmas everybody!

StarTeam and MS SQL Express 2005

A couple of days ago, I finally tried to set up Star Team 2005 R2. This version is included in Delphi 2006 Enterprise and Architect. At University, I was taught how to install and use CVS.

The first striking difference between CVS and StarTeam is that CVS does not use a database to store information at all. StarTeam (ST) uses in addition to the repository on the harddisk also one that is persisted in a SQL database. Borland deploys a Developer edition of MS SQL Server 2000 with Delphi (I am not sure which SKUs actually contain it, but I would guess Enterprise and Architect) as well, so you are ready to go if you bought D2006 Enterprise or Architect. However, I always like to experiment a bit and also wanted to check out Microsoft's new MS SQL Server. As I just wanted to fiddle around, I simply downloaded the Express edition, which is free right now.

Thus, before installing ST, I installed MS SQL Server 2005 Express. Of course, I needed to install .NET 2.0 for that. Afterwards I installed and configured ST. Reading the manuals (esp. the "Getting Started" one) before/while doing this is very much needed as you need to configure a lot of settings.

The result of my little experiment: It works perfectly. ST can create and maintain the databases in SQL 2005 Express without any problems. I have not had any issues at all using it.

Be aware that this is just my experience on a single system. I have no idea about side-effects that might occur when using ST with SQL 2005 with different setups esp. in companies where lots of people access the server at the same time. But I do think, as ST uses SQL statements to access the database, there should not be any issues. The only problem I anticipated was that ST simply might not "see" the new server and I might not be able to connect to it.

However, it was no problem at all.

Tuesday, December 13, 2005

Indy: IdHTTP

Just a quick note that I'll be publishing a TIdHTTP threading demo shortly. A user was asking in the public newsgroups how it was possible not to lock down the application by requesting ("GET") a document from the net.

Here's a screenshot to tease you:



The application is written in VCL.NET and uses a 3rd Party Component to display the HTML markup. The version I'll publish will use "Delphi Standard Components" instead, of course.

Tuesday, December 06, 2005

IntraWeb: new version 8.0 coming soon

I am a member of TeamZed, a group from Atozed (pronounce: A-to-Zed) which primarily has a look at upcoming software releases. Thus, I had the opportunity to have a look at the upcoming release of IntraWeb. It's going to be version number 8.0 and I think it will be released pretty soon, as the core development team is only fixing tiny setup issues right now.

Atozed Software already published some charts about the performance of the next release, which is going to be a huge improvement compared to earlier versions. You might have a look at them yourself.

I simply recompiled an IntraWeb Application, which I built using Delphi 2005 and I have to say that the performance really improved quite a bit, as you can feel a difference using the application without actually doing any performance measurements. I also noticed that the amount of data being transferred has been reduced quite a bit (almost 50% in my case).

So, if you have version 7.2.41 or even older, be sure to have a look at the new version!

Monday, December 05, 2005

German ECO Book online

While I was browsing through the public newsgroups I noticed http://www.ecospace.de being mentioned as a new portal for the German ECO Community.

I browsed there and guess what: you can download an ECO book about ECO II for free!

Considering that it is on a German page, you might have already guessed it is written in German. As I can read German just fine, I read a couple of pages and think it is really good.

Furthermore, I read reports from other German users on the net that they are fascinated with it and it helped them solve a lot of issues.

Thanks for the good work, Alois!

Blogging and Delphi source

As I have to remove the reference to the author of the code conversion tool I use to convert Delphi source into HTML, because my style sheet is not compatible with the tags being used, I hereby state that I use "HyperDelphi", which you can find here:
http://tinyurl.com/9djqz

ECO III: CurrencyManagerHandle



There is a nice difference between ECO II and ECO III that is not visible, but very helpful when developing ECO Applications.

Let's say you have a CurrencyManagerHandle called "cmTeam" then you get the "selected" element in a grid, which is of the class type "Team" (if a DataGrid is the BindingContext) using:

aTeam := Team( cmTeam.Element.AsObject );

Problem: What happens if nothing is selected?
Solution: check if cmTeam.Element.AsObject is not equal to nil!

Be careful as it was more complicated in ECO II, this will only suffice in ECO III!

So to get an object of class "Team" of a list of teams in a grid you will have to use:

if ( Assigned( cmTeam.Element.AsObject ) ) then
begin
myTeam := Team( cmTeam.Element.AsObject );
....
end
else
// throw exception....
;



For the record: In ECO II you have to check for cmTeam.Element not equal to "nil" first.

ECO and Databases

Talking to other developers I often find out that ECO is marked an "object persistence tool" which makes it possible to store objects in databases. I have been unable so far to summarize the features of ECO in one sentence, but it is definitely not a framework that is designed to make it easier to store objects of modeled classes in a database.

The reason for that is that a lot of people , like myself, automatically think of databases, tables, relations and views when working with ECO. It's not easy to wipe that from memory, but when getting started with ECO, you simply have to forget that you will persist it inside of a database later on. Let ECO take care of that. Your task, in order to reach maximum success using ECO, is to model using UML. I wrote the keyword in italics. As Jan Norden put it perfectly: The Model is The System!

Let's finish off this blog post with an example. If you persist a blog entry in a database, you'd think of the attributes that make up a blog entry. So you need
  • an author
  • a creation date
  • a title
  • and content.
Ok. So we end up with a class called "BlogEntry" in ECO with four attributes named "author", "created", "title" and "body" (I learned that database designers always call the content "body" :-) ).



Is this a proper conceptual ECO model? Yes, it is proper. But it limits your abilities. How would you list blog entries of a certain author? How would you list all blog entries of one day? "OCL expression using select" you say. Correct, but not that handy. ECO can do it easier. Let me show you this model:



Now you can list all different authors easily and what is even more important: you can change the number of possible authors with one keystroke in the model! Furthermore, rename "CreationDate" into "DateHistory" and thus make it possible to associate many dates with one blog entry. This way you can list all dates when the blog entry was modified.

Would it be possible to transfer this model to a database easily? No. But that's what we have ECO for... It's there to persist objects into databases after all, isn't it? *grin*

Friday, December 02, 2005

Coding "Standards" - The Summary

Firstly, let me tell you that I was positively surprised that I got so many comments on that subject. But I should clarify one thing: I was surprised not that there were coding standards for Delphi in general, but about the fact that Borland has an official document on BDN.

What I learned because of all the comments is that this document can be found in the help, which comes with Delphi, as well. That surprised me even more, as I never noticed it.... using Delphi since version 2. Furthermore, I was flamed by my fellow Indy Core team-mates that I forgot to mention that Indy - of course - has its own coding standard as well. Have a look at it here.

Finally, I'd like to stress that Delphi 2006 really helps you to implement a certain standard using Code Templates. Depending on how you modify the templates for basic constructs like "if" or "for" you can make sure that you get the right level of indentation or that the cursor is positioned right below the "if" to type in the begin... Of course, you can also define a complete if-construct that already has "begin" and "end;", but if you implement code like me, you do not always use a "begin" and "end"-block. This is e.g. a rule in the Indy Coding Standards to always use "begin" and "end". Be it needed or not.

I guess, I could make up a whole blog about different coding standards and related issues.

Again, thanks for all the feedback.

Thursday, December 01, 2005

ECO: Associations

If you've ever designed an ECO app, you might have been annoyed how clumsy it was to change the multiplicity between classes. With BDS 2006 it's become so easy. Simply click on the multiplicity and it is being focused:



And finally, press "F2" to go into edit-mode and change "0..1" into "0..*" e.g. to get a 1-to-many relation:



That's easy, isn't it?

ECO: How to add State Machines

I was really blown away, seeing all the new Together stuff in BDS 2006 from an ECO perspective. Firstly, all the new things you can add, which are mostly because of the addition of State Machines.

Adding a State Machine is really simple. Right-click a class and choose "Add / ECO State Machine".



Do not right click the model surface as a State Machine determines the state of an attribute inside of a class.


Notice that if you add a State Machine, you will also end up with a State Attribute in your class automatically, which is automatically linked to that very State Machine, which you added before:



It is being named "State_x" by default and can be renamed, of course. I plan to post a basic "demo" of State Machines shortly.

Let me know if you're interested!

ECO: Where are CoreClasses?

If you create a new ECO project, which personality or platform you might choose does not matter, the Model View looks different in BDS 2006 compared to D2005. The default ECO Package is no longer named "CoreClasses".

The far more intuitive name "Package_1" is being used. Furthermore, I think it's better classified as a "package" this way, as you have your final classes in separate or one source file(s).



Basically, you can safely double click on "Package_1" instead of "CoreClasses" in order to open your first ECO model.