Friday, November 30, 2007

String parameters tip

Chris Bensen has a 'small' tip, which in fact is a great tip.
He suggest to always pass strings as const or var. If you pass them by value extra (unnecessary) assembly is being generated.

Read his blogpost String parameters in delphi (Don't forget the comments)

Thursday, November 22, 2007

Some memory leak pitfalls

Just installed the professional version of Eurekalog, which is, imo, a must have tool for tracking exceptions and memory leaks in your Delphi Win32 applications.
This tool, and of course any other tool out there that does the same, really helps you to track down exceptions fast. For me, even more important, is the fact that it helps you track down memory leaks as well.

No matter how secure you program, sooner or later, you will loose some memory. Here some pitfalls:

1. Let it be clear where, and who, will free the object
It must be clear where objects are created (read memory for the object is allocated) because otherwise you are in danger for memory leaks.
Functions that create their result are dangerous in this manner. Suppose a function that creates a TStringList, and returns it as it's result:

function TForm3.GetSomeStringList : TStrings;
begin
Result :
= TStringList.Create;
Result.Add(
'one');
Result.Add(
'two');
end;

procedure TForm3.DoSomethingWithaStringlist;
var
MyStringList : TStrings;
begin
MyStringList :
= GetSomeStringList;
try
ShowMessage(MyStringList.Text);
finally
MyStringList.Free;
//Free it!
end;
end;

In this case, the calling method, and the developer must realize that it must free the stringlist, after it is ready with it. This is not always clear in this scenario. A better solution would be to pass your own created Stringlist to the function. Like this:
procedure TForm3.GetSomeStringList(
AStringList : TStrings);
begin
AStringList.Add(
'one');
AStringList.Add(
'two');
end;


procedure TForm3.DoSomethingWithaStringlist;
var
MyStringList : TStrings;
begin
MyStringList :
= TStringList.Create;
try
GetSomeStringList(MyStringList);
ShowMessage(MyStringList.Text);
finally
MyStringList.Free;
//Free it!
end;
end;


It is better to have both, the Create and Free in the same try finally block if possible. Can't go wrong if you code it like this.


2. Always free your own objects nobody else does it for you 
Sometimes it is easy to add to, for example a listbox, also an extra object with more information of the selected item. When filling the items (a TStringlist) you pass on a reference to the listbox item. Later you can use that information to do, whatever you want to do.


Your code could look like this:

procedure TForm3.Button1Click(Sender: TObject);
var
obj : TSomeObject;
begin
obj :
= TSomeObject.Create;
obj.SomeInfo :
= 'This is number one';
ListBox1.Items.AddObject(
'one', obj);
obj :
= TSomeObject.Create;
obj.SomeInfo :
= 'This is number two';
ListBox1.Items.AddObject(
'Two', obj);
end;

To read the data on the selection you can then read the extra info like this (just an example here):
ShowMessage(
(ListBox1.Items.Objects[ListBox1.ItemIndex]
as TSomeObject).SomeInfo);

What you must not forget in this situation is to free all the objects when the application or form is destroyed! The Listbox does not do that for you!

So in the destroy of your form, free all the objects in the listbox like this:
for i := 0 to ListBox1.Items.Count - 1 do begin
Listbox1.Items.Objects[i].Free;
end;

Conclusion is that a good coding style helps you to avoid memory leaks. Tools like Eurekalog helps you to trace them easily and are a great learning resource for where you enter memory pitfalls

Wednesday, November 14, 2007

Time to shift to second gear

CodeGear exists one year!

I could sum up everything that happened this year, but Marco Cantu did a great job in his blogpost One year for CodeGear. (Very nice read!)

CodeGear congrats! And let's shift to second Gear shall we?

Wednesday, November 07, 2007

BugNET review, download, install and track your issues!

Bug tracking is a very important part of software development. We do projects for a lot of different company's which almost all have their own way of bugtracking, if they have it all.
Basically bugtracking is maintaining a list of issues, administering some dates, like report date to solved dates.
When you work in small teams (<3 person) a simple Excel list will do it, but in greater teams, on different locations it just becomes a mess.

Time to investigate a better solution, a bugtracking system.

We had a few requirements:
- The tool should be web based (Running on IIS)
- Projects with team members and roles
- Projects/Users only available for assigned persons
- Possibility to add fields for a specific project on the fly
- E-mail notifications for status changes etc.
- Not only suitable for bugtracking, but issue tracking in general
- If open source then ASP.NET C# as first choice
- Fast and nice looking

BugNET
The first open source project we tried was BugNET

BugNET is an issue tracking and project issue management solution built using the ASP.NET web application framework. Email notifications, reporting and per project configuration of fields and values allows efficient management of bugs, feature requests, and other issues for projects of any scale.

We downloaded it, installed it and loved it! Within 10 minutes we had an Issue tracking solution that met all of our requirements!

In BugNET you can create projects, assign team members to it giving them a standard role from Project Manager to Reader. You can also create own roles per project. A project can have categories (for instance the modules of an application) and versions that can be used as milestones for the issues. Those milestones easily translates themselves into a roadmap.
The project summary page gives a good overview with, from left to right, open issues per milestone, per category, per assignee, per status, per priority and type.
Issues can have:
- Comments
- Attachments
- Related issues
- and even time tracking

Issue changes can be notified by e-mail, and even RSS.
BugNET also supports a report solution which allows you to report to screen, PDF and Excel.
The user interface is looking nice, clean and to the point.

BugNET has the following requirements:
- IIS 5 or later
- Microsoft .NET Framework v2.0 Redistributable
- Microsoft Report Viewer Redistributable 2005
- Microsoft ASP.NET AJAX 1.0
- Microsoft SQL Server

More on the installation can be found on the BugNET documentation page.

If you are looking for a issue(bug) tracking management solution you really should give BugNET a try!

Use an image as your UIBarButtonItem

Using an image as your UIBarButtonItem in your navigationcontroller bar can only be achieved by using a common UIButton as the BarButtonItem...