Swimming World Championships: Delphi Software swim in it

Delphi for Win32, Events, bit Time Software 4 Comments »

From July 17th to August 2nd, The Foro Italico (in Rome) will be the heart of the 13th FINA World Championships Roma 2009, for swimming, diving, synchronised swimming and water polo. Four permanents pools and two temporary pools will be the set of the competitions for the four competitive disciplines, and all the venue will turn into a village that will host and entertain all night long over 400.000 people during 17 days of contests.

2009 Swimming World Championships

Now you are thinking: where is Delphi ?

Delphi is used (as usual) without knowing you are using it.

A software built with Delphi is used to manage the opening ceremony.
This software is designed to do the very complex attendee placement in the audience and to automate the invitation process.
The attendees will be VIP from Italy and international countries, starting from the italian president, the highest authority in Italy.

Cerimoniere

Cerimoniere

You can have a look at the software CERIMONIERE here (but the site is in Italian, sorry)

I actively participated in the design and development of this software, and now that I see it in action, in a so important and internationally well known event, I’m very proud of it, and I’m sure any member of the great Delphi community will be as well.

Delphi Developer Days

Delphi for Win32, Events, Non Tech, bit Time Software 1 Comment »

When I was at Delphi Live in San Jose, I attended Marco Cantù and Cary Jensen Masterclass about Delphi Multithreading.
Although, I’m expert of multi threading techiques and the related problems, this masterclass was very interesting and well organized as well.

IMHO, the topics have been presented in very effective manner and, as usual, in a very professional way.

After their speech, Marco introduced me to “Delphi Developer Days”.

I’ll do my best to attend their event in London.

Following some references in case you want also attend:

Delphi Developer Days 2009 London
Top Delphi experts Marco Cantù and Cary Jensen are bringing
their two-day live seminar to London on July 1-2, 2009.
For complete, details, visit http://www.DelphiDeveloperDays.com

Delphi profiling made simple… really simple!

CodeGear, Delphi for Win32, Programming, Uncategorized 5 Comments »

Many users asked Embarcadero to include a profiler in the next Delphi for Win32.

Waiting for this, there are some interesting tools for profile a Delphi program.

For example, AsmProfile is an Open Source sampling profiler wich is very simple to use.

UPDATE:

Actually AsmProfile is an “Instrumenting” profiler. It uses runtime function detouring and assembly to profile any selected function.

If you dont know differences between Instrumenting profiler and Sampling profiler, you can go here or here and read about it.

So, Suppose to have a slow code like this:

Download AsmProfiler from SVN or project home page (see the end of the article).

Now you can put 2 unit in your uses clause and initialize profiler interface directly in your dpr

So far so good… compile your app with following settings:
Delphi -> Project Options:

  • Linker -> Map file = detailed
  • Compiler -> Optimization = off
  • Compiler -> Stack frames = on

In this way, the profiler can reach procedures address for profiling phase.
Run your application and a small form will show up. In this form your must select the profiled methods and then click “Start”.

Now stress your application, click “Stop” and then “Show Results”.
In the “results” form will be shown detailed information about program execution.

Every call timing is splitted in “Calls”, “Parent Calls” and “Child calls” and some stats has been calculated too.

AsmProfiler It’s not complete like AQTime from AutomatedQA, but it’s a very usefull tool for every Delphi programmer.

You can find AsmProfiler here but I suggest to download the updated SVN version.

UPDATE:

AsmProfile can also profile your code without change source using DllInjection.

When you only have an executable:

  • Start your executable
  • Start “dllinject.exe” (will show up a console window)
  • Get the PID of your executable via Windows Task Manager or Sysinternal Process Exlorer
  • Enter this number in the console black
  • Start profiling

A Simple start with MVP in Delphi for Win32, Part 1

CodeGear, Delphi for Win32, Design Patterns, MVC, MVP, Programming, Uncategorized 11 Comments »

As GUI framework such as VCL become more and more powerful, it’s common practice to let the UI layer do more than it should. Without a clear separation of responsibilities, the UI layer can often become an integral part of application and businness logic, but… this kind of responsabilities belongs to other layers of the application.
A design pattern (and his numberless variants), is especially well suited to solving this problem.

In this article I want to build a simple application using MVP pattern. Actually, pattern used is not “clear” MVP but his variation called Passive View.

Using Fowler words:

A perennial problem with building rich client systems is the complication of testing them. Most rich client frameworks were not built with automated testing in mind. Controlling these frameworks programaticly is often very difficult.

A Passive View handles this by reducing the behavior of the UI components to the absolute minimum by using a controller that not just handles responses to user events, but also does all the updating of the view. This allows testing to be focused on the controller with little risk of problems in the view.

Passive View ensures no dependecies between Model and View.

Passive View has no dependencies between view and model (Unlike most MVC-style triad)

Passive View has no dependencies between view and model (Unlike most MVC-style triad)

In this sample, “model” is a simple layer for application logic. In real world, “service layer” should incapsulate “application service” and “domain model“.

Application looks like following:

The Calculator

The Calculator

Div operator with result

Div operator with result

Div operator with a EDivByZero Exception

Div operator with a EDivByZero Exception

Connect View and Presenter
The view (the Form in VCL application) must implement an interface.

This interface should provide all method to interact with GUI:

  1. ICalculatorView = interface
  2.   ['{471E3657-C6CE-49A3-BCB4-8FA6AF611DAD}']
  3.   function FirstOperand: String;
  4.   function SecondOperand: String;
  5.   procedure SetFirstOperand(Value :String);
  6.   procedure SetSecondOperand(Value :String);
  7.   function GetOperator: IGUISelectableList;
  8.   procedure SetCalcResult(const Value: String);
  9.   procedure SetCalcResultReadOnly(const Value: Boolean);
  10.   function Error: IGUIEdit;
  11. end;

For simple interacting with GUI widget (in our example are EditFirstOperand, EditSecondoperand and EditCalcResult) we use a simple methods like following

  1.   function FirstOperand: String;
  2.   function SecondOperand: String;
  3.   procedure SetFirstOperand(Value :String);
  4.   procedure SetSecondOperand(Value :String);

But, if we need more by our widget (like populating combo box or change font color in the EditError or set ReadOnly to true) we should use another interface for a family of component.
In this sample I wrote 3 general interface:

  1.   IGUIBaseInterface = interface
  2.     ['{F0B7F031-9302-415E-8545-1FE20A365840}']
  3.   end;
  4.  
  5.   IGUIEdit = interface(IGUIBaseInterface)
  6.     ['{FE2D56FB-0CFB-4B33-9B56-0A523B235D37}']
  7.     procedure SetText(const Value: String);
  8.     function GetText: String;
  9.     function GetAsInteger: Integer;
  10.     function GetAsFloat: Extended;
  11.     procedure SetReadOnly(const AValue: boolean);
  12.     procedure SetVisible(const Value: Boolean);
  13.     function GetTextAsInteger: Integer;
  14.     procedure SetTextAsinteger(const Value: Integer);
  15.     function GetTextAsFloat: Extended;
  16.   end;
  17.  
  18.   IGUISelectableList = interface(IGUIBaseInterface)
  19.     ['{EEFE5C52-94C3-464B-80F2-05E443B0F0F6}']
  20.     procedure SetText(const Value: String);
  21.     function GetText: String;
  22.     procedure SetValue(const Value: String);
  23.     function GetValue: String;
  24.     function GetSelected: ISSKeyValue;
  25.     procedure AddPair(AKey, AValue: String);
  26.     procedure Clear;
  27.   end;

For implementation details see attached sample code.

Finally in FormCreate of our form we can wire Presenter and View:

  1. TfrmCalculatorView = class(TForm, ICalculatorView)
  2.   //code
  3. end;
  4.   //interface section
  5. procedure TfrmCalculatorView.FormCreate(Sender: TObject);
  6. begin
  7.   //Link controls with related interface
  8.   IOperators := TGUISelectableList.Create(ComboOperators);
  9.   IError := TGUIEdit.Create(EditError);
  10.  
  11.   //link view and presenter
  12.   //In this version VIEW know PRESENTER
  13.   FPresenter := TCalculatorPresenter.Create(Self);
  14. end;

This is a very simple example, so not all looks like real world. In a real world application, for example, view should not known the presenter class. With dependency injection you can do that (Next article in this serie will talk about this).

Every event generated by View (our Form) must be redirected to Presenter.

  1. procedure TfrmCalculatorView.Button1Click(Sender: TObject);
  2. begin
  3.   FPresenter.DoCalc;
  4. end;

Another approach is to publish some events in view interface and let presenter to bind them via standard event handler or anonimous methods (but this is for another post).

In attached sample code there is a sample application and unit test for Service Layer and View.
Required Mock Library is included in the zip file.

Simple Passive View, Sample Code

In 2nd part I’ll talk about unit test and mock object in Passive View.

.NET databinding in Delphi for Win32

CodeGear, Delphi for Win32, Design Patterns, MVP, Programming, Uncategorized 3 Comments »

Databinding is defined as: “General technique that binds two data/information sources together and maintains them in sync. This is usually done with two data/information sources with different types as in XML data binding. However in UI data binding, we bind data and information objects of the same type together (e.g. Java objects to Java UI elements).”

Databinding is common technique in VCL. Since Delphi 1 we have TDataset class for bind data and UI controls (DB Aware) in a GUI application.

In .NET world, instead, databinding is very different.

So, I’m starting to write (actually for fun) a DataBinder component to use .NET “like” databinding (or something similar to) in Delphi for Win32 too.

All the code has been written in about 2 hours.

TDataBinder

With this component you can “bind” an object property to another object property in a declarative mode.

e.g.

  1. DataBinder.Add(Person, 'FirstName', Edit1, 'Text');

and then, every update to Person.FirstName property, will be reflected in the Edit1.Text property.

You can bind different control properties to different BO properties.

e.g.

  1. //Text = FirstName
  2. DataBinder.Add(Person, 'FirstName', Edit1, 'Text');
  3. //If Person is not married, TEdit become flat
  4. DataBinder.Add(Person, 'IsMarried', Edit1, 'Ctl3D');

So in your initialization code (e.g. FormCreate) you can write somethig similat to following:

  1. procedure TForm3.FormCreate(Sender: TObject);
  2. var
  3. binder: TDataBinder;
  4. begin
  5. //Create your "BO"
  6. Person := TPerson.Create;
  7. //read data from "database"
  8. Person.Load;
  9.  
  10. //Setup databinding…
  11. binder := TDataBinder.Create(self);
  12. binder.Add(Person, 'FirstName'   ,      Edit1,     'Text');
  13. binder.Add(Person, 'LastName',          Edit2,     'Text');
  14.  
  15. //The same attribute binded to 3 controls
  16. binder.Add(Person, 'Married',     CheckBox1, 'Checked');
  17. binder.Add(Person, 'Married'   , Edit1,     'Ctl3D');
  18. binder.Add(Person, 'Married',     Edit2,     'Ctl3D');
  19.  
  20. //The same attribute binded to 2 controls
  21. binder.Add(Person, 'SomeInteger', ComboBox1, 'ItemIndex');
  22. binder.Add(Person, 'SomeInteger',     TrackBar1, 'Position');
  23.  
  24. //A derived property
  25. binder.Add(Person, 'FullName',     Panel1, 'Caption');
  26.  
  27. //let start…
  28. binder.Bind;
  29. end;

Other info asap so, stay tuned.

Download Code and compiled sample

(Source code require Delphi 2009)

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in