ITDevCon 2014, Call4Papers

ITDevCon 2014
ITDevCon 2014

Dear potential ITDevCon speaker,

As every year, I’m building the agenda for next ITDevCon that will be held next october 23th, 24th in Milan (Italy), in a new location.

This will be the 6th edition ( we’re getting conference experts J )

The call for papers are officially open right now, so if you want to propose some speeches, I’ll be glad to see it.

As usual, for the Call4Paper I need:

  • Title (for every talk)
  • Abstract (for every talk)
  • Difficulty level (for every talk. Difficulty level is a scale from 1 to 3 with the following mean: introduction, intermediate, advanced)
  • Speaker’s photo
  • Speaker’s profile

I’m looking forward to your proposal. The call4papers ends at Aug 31st, 2014 but if you have *VERY* interesting topic to propose, propose it… I’ll try to arrange the schedule and fit it in the agenda.

Send your proposal to call4paper(at)itdevcon.it.

Proposals will be evaluated and the speakers will be contacted ASAP.

This year topics will be the following:

TOPICS

  • What’s new in the latest Delphi versions

  • FireMonkey platform

  • MacOSX development

  • Android development

  • iOS development

  • Windows development

  • Mobile development (Android+iOS)

  • Develop UIs for different devices (smartphones, tablets, TV, watch etc)

  • BaaS integrations

  • LiveBindings ®

  • Delphi best practices

  • Design Patterns

  • DataSnap

  • DelphiMVCFramework

  • Arduino e/o Raspberry Pi

  • Web Application with Delphi

  • TDD and Unit Tests

  • Agile methodologies

  • ORM and other data access patterns

  • Using NoSQL databases (even to speed up your VCL software)

  • FireDAC

  • UI, UX, optimization for mobile and desktop

  • OOD/OOP

  • Real use cases for extended RTTI, Generics e AnonMethods

  • RESTful interfaces design and development

  • Architectures

Target audience

  • Software architects
  • Software developers
  • Project managers
  • IT managers
  • Trainers

The conference web site is http://www.itdevcon.it (2014 version is still under construction).

Do you want to see a particular topic or have a suggestion for ITDevCon2014? Let me know

Thanks and see you at ITDevCon 2014.

Delphi MVC Web Framework – “Hello World”

This is the first “Hello World” for my Delphi MVC Web Framework.

program DelphiMVCWebFramework;

{$APPTYPE CONSOLE}

uses
  System.SysUtils,
  MVCEngine in 'MVCEngine.pas',
  BaseController in 'BaseController.pas';

var
  mvc: TWebMVCEngine;
begin
  mvc := TWebMVCEngine.Create;
  mvc.AddRoute('/', procedure(Context: TWebContext)
    begin
      Context.Write('Hello World');
    end).Start(8080);
  ReadLn;
  mvc.Free;
end.

Features list (some of them are in the internal roadmap)

  • Completely MVC
  • Addressable with servername/controllername/actionname?par1&par2
  • Addressable with servername/controllername/actionname/par1/par2
  • Can also use anonymous methods as actions for very simple app (in the sample)
  • Really RESTful (Level 3 of the Richardson Maturity Model)
  • Fully integrable into WebBroker and DataSnap
  • Supports multiple resource rapresentations
  • Completely customizable routing using internal formatting or regex
  • Inspired to ASP.NET, Sinatra, Java Spring MVC, Java Restlet
  • Scriptable views support (Pascal, Razor, Lua)
  • Component based
  • Session support
  • ORM support using dorm
  • Classic TDataSet support
  • State server to support real loadbalancing using reverse proxy
  • Can be deployed as standalone (in the example), ISAPI dll and Windows Service
  • Fully support https
  • More to come…
  • This framework is still under development.

    Are you interested in? :-)

    UPDATE:

    The project is open source and you can fint it here

    https://code.google.com/p/delphimvcframework/

In the core of LiveBindings expressions of RAD Studio XE2

WARNING! I’ve been authorized by EMBARCADERO to write about RAD Studio XE2.

RAD Studio XE2 is full of nice and exciting features. One of the most awaited of them is the LiveBindings.

The LiveBindings is available to the VCL and the new FireMonkey framework and allows to connect a property object to another using an expression and a set of observers.
Let’s say Edit1.Text “is binded to” Person1.Name also in a bidirectional way. The “link” between a property (or a group of properties) and another property can also be very complex.

The following is an example of a complex bind expression that return a value:

"This is a full name: " + Trim(ToUpperCase(FirstName)) + ", " + Trim(ToUpperCase(LastName))

I’ve waited LiveBindings for ages and now they are here!

So, let’s look a deep inside to the core of livebindings expression evaluator,
the TBindingExpression.

The TBindingExpression is an abstract class that allows to evaluate an expression. But, what’s an expression? An expression is a string that return, or not return, a value. You could see an expression as a little function or procedure.
To explain the concept, I’ve build a simple expression interpreter using an XE2 beta version.

It is very simple but shows the power of expression engine.
This is the scriptengine while evaluates a simple arithmetic expression.

The expression engine is not only a “static” evaluator. Using the powerful Delphi RTTI introduced in Delphi 2010, you can also allows the expression to “read” and “call” property and method of your Delphi objects!!

So, now, some code is needed.

As you can see, you can “register” some association between a real object and an alias in the expression. So, if my object are declared as the following:

I can use a expression as the following:

Going further, you can call methods in your expression!

So, if you have methods declared as following:

You can use the following expression:

Obviously, when you link a property to another you should not use dialogs in the expressions, but this feature is VERY powerful.
You can create different expression and use them as a custom calculator for specific business rules. The expressions are strings, so you can store them in a file or in a database and use them as needed. The expression engine is not a complete scripting language, but it can be used (and abused) in a very broad range of situations.

For complex business rules, I hate the classic chain

Data->TDataSet->DBAware

so I usually use a DomainModel that use datasets only to read data.

The LiveBinding allows me to use (for complex business rules) the following chain

Data->ORM->DataObjects->Bindings->VisualControls

This is only an introduction to the LiveBingind engine. ASAP I’ll post other articles about it.

I’ll talk about the livebinding engine at the ITDevCon2011 conference. Will be you there?

RAD Studio XE2 will be officially presented all over the world during the “RADStudio XE2 World Tour”.
You can find the list of all launch events in the RADStudio XE2 World Tour page.

I’ll be a presenter at 3 launch events in Italy and United Arab Emitates.
These are the events where I’ll be (click to register):

  • 19th Dubai, United Arab Emirates
  • 21nd Milan, Italy
  • 22nd Rome, Italy

Stay tuned.

Sneak preview about DORM, The Delphi ORM

My yesterday post about this busy time, have raised some interest about DORM, the Delphi ORM.

So, also if I still haven’t released any files, wish to expose some internals about DORM.

DORM is an implementation of the DataMapper design pattern written having Hibernate in mind.

It’s completely unit tested and have the following features:

  • External file mapping. (JSON format)
  • Persistence ignorance (every TObject can be persisted)
  • Support for One-One and One-Many relations (still no many-many)
  • Support for LazyLoading (you can enable§/disable lazyloading by file or by code by per-basis needs)
  • Support for IdentityMap
  • Support for custom “finder” (you can still use complex SQL if you want)
  • Complete support for CRUD
  • Transactions
  • Built in logging system to log *EVERY* sql or action performed by the framework
  • Opened to multiple data access strategies (interfaced based, not inheritance based) for use with different database (now I’ve developed the firebird one using DBX)
  • Caching for RTTI (the TSession object have a single TRttiContext holding ALL metadata)

Code is still under heavely development.

Those are 2 test-method to show the use of DORM:

TPerson = class(TObject)
...
property Phones: TdormCollection.... //implements IList
end;
 
TPhone = classs(TObject)
...
end;
 
//and now the unit tests
 
procedure TTestDORMHasMany.Setup;
begin
  Session := TSession.Create;
  Session.Configure(TStreamReader.Create('dorm.conf'));
end;
 
procedure TTestDORMHasMany.TearDown;
begin
  Session.Free;
end;
 
procedure TTestDORMHasMany.TestHasManyLazyLoad;
var
  p: TPerson;
  t: TPhone;
  guid: string;
begin
  p := TPerson.NewPersona;  //static method. Return a fully populated TPerson object
  try
    t := TPhone.Create;
    p.Phones.Add(t);
    Session.Save(p);
    guid := p.guid;  //GUIDs, or other PK types, are generated automagically by DORM. Obviously there is a specific class loaded to do this specified in the dorm.conf file)
  finally
    Session.Commit;
  end;
  Session.StartTransaction;
 
  // Test with lazy load ON
  Session.SetLazyLoadFor(TypeInfo(TPerson), 'Phones', true);
  p := Session.Load(TypeInfo(TPerson), guid) as TPerson;
  try
    CheckEquals(0, p.Phones.Count);
  finally
    Session.Commit;
  end;
 
  Session.StartTransaction;
  // Test with lazy load OFF
  Session.SetLazyLoadFor(TypeInfo(TPerson), 'Phones', false);
  p := Session.Load(TypeInfo(TPerson), guid) as TPerson; // Without commit, AV becouse IdentityMap doesn't work properly
  try
    CheckEquals(1, p.Phones.Count); // Child objects are loaded
  finally
    Session.Commit;
  end;
end;
 
procedure TTestDORMHasMany.TestLoadHasMany;
var
  list: IList;
  t, t1: TPhone;
  p: TPerson;
  guid: string;
begin
  p := TPerson.NewPersona;  //static method. Return a fully populated TPerson object
  try
    t := TPhone.Create;
    t.Numero := '555-7765123';
    t.Kind := 'Casa';
    p.Phones.Add(t);
 
    t1 := TPhone.Create;
    t1.Number := '555-7765123';
    t1.Kind := 'Casa';
    p.Phones.Add(t1);
    Session.Save(p); // save Person and Phones
    guid := p.guid;
  finally
    Session.Commit;
  end;
 
  Session.StartTransaction;
  p := Session.Load(TypeInfo(TPerson), guid) as TPerson;
  try
    CheckEquals(2, p.Phones.Count);
  finally
    Session.Commit;
  end;
end;
 

Mapping, contained in a file called “dorm.conf”, is similar to the following:

{
  "persistence": {
    "database_adapter": "dorm.adapter.Firebird.TFirebirdPersistStrategy",
    "database_connection_string":"127.0.0.1:C:\MyProjects\DORM\experiments\dorm.fdb",
    "username": "sysdba",
    "password":"masterkey"
    },
  "config": {
    "package": "dorm.bo.Person",
    "logger_class_name": "dorm.loggers.FileLog.TdormFileLog"
  },      
  "mapping":
    {      
      "TPerson":
      {
        "table": "people",
        "id": {"name":"guid", "field":"guid", "field_type":"string", "size": 100, "default_value": ""},
        "fields":[
          {"name":"firstname", "field":"first_name", "field_type":"string", "size": 100},
          {"name":"lastname", "field":"last_name", "field_type":"string", "size": 100},
          {"name":"age", "field":"age", "field_type":"integer"},
          {"name":"borndate", "field":"born_date", "field_type":"date"}
          ],
        "has_many":[{
          "name": "Phones",
          "class_name":"TPhone",
          "child_field_name":"guid_person",
          "lazy_load": false
        }],
        "has_one": {
          "name": "car",
          "class_name":"TCar",
          "child_field_name":"guid_person"
        }
      },
      "TPhone":
      {
        "table": "phones",
        "id": {"name":"guid", "field":"guid", "field_type":"string", "size": 100, "default_value": ""},
        "fields":[
          {"name":"number", "field":"number", "field_type":"string", "size": 100},
          {"name":"kind", "field":"kind", "field_type":"string", "size": 100},
          {"name":"guid_person", "field":"guid_person", "field_type":"string", "size": 100}
          ]
      }
    }
}

The PODO (Plain Old Delphi Objects) can be binded to the VCL controls with a set of MediatingView (Model-GUI-Mediator Pattern) with an Observer mechanism to mantain things in synch.

Any comments? Someone interested?

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

Some month ago I wrote a simple article about an MVP variant called PassiveView.
That example was very simple. Now I’ll present a more “advanced” version of that example.

The main problem with first example was the following method:

procedure TfrmCalculatorView.FormCreate(Sender: TObject);
begin
  //Link controls with related interface
  IFirstOperand := TGUIEdit.Create(EditFirstOp);
  ISecondOperand := TGUIEdit.Create(EditSecondOp);
  ICalcResult := TGUIEdit.Create(EditResult);
  IOperators := TGUISelectableList.Create(ComboOperators);
  IError := TGUIEdit.Create(EditError);

  //link view and presenter
  FPresenter := TCalculatorPresenter.Create(Self); //<<-- THIS IS THE BAD LINE
end;

The “BAD” line links the View with the Presenter but it’s in the view code, so this is meaning that View KNOWS the presenter… and this is not a good thing becouse the view is not so “passive”.

In a more advanced (and complex) version the View should be completely ignorant about the class that implement the presenter and the service.

In the main dpr file now the code now looks like the following.

var
  MainPresenter: ICalculatorPresenter;
  CalculatorView: TForm;
begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  //SETUP THE MAIN APPLICATION FORM FOR VCL PURPOSE
  Application.CreateForm(TfrmCalculatorView, CalculatorView);  
  //SETUP ALL THE LINKS BETWEEN THE MVP TRIAD
  MainPresenter := TCalculatorPresenter.Create(CalculatorView as ICalculatorView, TCalculatorService.Create);
  //LETS START!
  Application.Run;
end.

Now the presenter take care about all links between the MVP triad.

constructor TCalculatorPresenter.Create(CalculatorView: ICalculatorView;
  CalculatorService: ICalculatorService);
begin
  inherited Create;
  FCalculatorService := CalculatorService;
  FCalculatorView := CalculatorView;
  FCalculatorView.SetPresenter(self);
  InitView;  //does the links
end;

There is another addition to the previous example. Now there is only one constructor in the presenter, and using dependency injection take 2 interface for the view and the service.

    constructor Create(CalculatorView: ICalculatorView; CalculatorService: ICalculatorService);

Another plus is the possibility to open the same form a number of times without change the code for create it.

This is the GUI for this simple application.

3 instance of the same view with different presenter and service
3 instance of the same view with different presenter and service

As bonus, unit tests and mock object arent changed.

As usual the source code is here.

A simple Dependency Injection Container for Delphi

As wikipedia says:

“Dependency injection (DI) in computer programming refers to the process of supplying an external dependency to a software component. It is a specific form of inversion of control where the concern being inverted is the process of obtaining the needed dependency. The term was first coined by Martin Fowler to describe the mechanism more clearly.

Many of us have already read this historical article from Martin Fowler about dependency injection pattern, but actually there isn’t a real framework for implement dependency injection in Delphi.

There are already the following implementation for DI in Delphi

  • Emballo (work with pre-D2010 too, but the implementation require changes in the service classes. I really hate it)
  • Delphi Spring Framework (very nice, but still not realeased)

So, I decided to write my own simple DI framework.

You can find the code at google code project here: http://code.google.com/p/delphidicontainer/

This is the first public version and come with sample, documentation and unit tests.

Folow some sample code.

program Test01;
{$APPTYPE CONSOLE}

uses
  SysUtils,
  DIContainer in '....srcDIContainer.pas',
  ServiceTestObjectsU in '....UnitTestServiceTestObjectsU.pas';

var
  DIContainer: TDIContainer;
  s1: TService1;
  s2: TService2;
  s3: TService3;
  s6: TService6;
  s7: TService7;
begin
  try
    DIContainer := TDIContainer.Create;
    try
      // AddComponent with TClass with and   InitType = Singleton
      DIContainer.AddComponent(TService1, TDIContainerInitType.Singleton);
      // AddComponent with QualifiedName and InitType = Singleton
      DIContainer.AddComponent('ServiceTestObjectsU.TService2',
        TDIContainerInitType.Singleton);
      // AddComponent with QualifiedName and InitType = CreateNewInstance
      DIContainer.AddComponent('ServiceTestObjectsU.TService3',
        TDIContainerInitType.CreateNewInstance);

      // GetComponent with QualifiedName
      s1 := DIContainer.GetComponent('ServiceTestObjectsU.TService1')
        as TService1;
      s1.Message := 'I''m the first message';
      WriteLn(s1.Message);

      // GetComponent with TClass
      s2 := DIContainer.GetComponent(TService2) as TService2;
      s2.Message := 'I''m the second message';
      WriteLn(s2.Message);

      // GetComponent with a dependent service (TService3 depends upon TService1 and TService2)
      s3 := DIContainer.GetComponent('ServiceTestObjectsU.TService3')
        as TService3;
      WriteLn(s3.GetCompoundMessage);
      // s3 is not created as Singleton, so after use it I must free it
      s3.Free;

      // AddComponent with QualifiedClassName, a custom initializer, an alias.
      // Component will be created as singleton (single instance managed by Container)

      DIContainer.AddComponent(DIContainerUtils.GetQualifiedClassName
          (TService6),
          function: TObject
          begin
            Result := TService6.Create(DIContainer.Get(TService1) as TService1,DIContainer.Get(TService1) as TService1);
          end,
          'srv6',
        TDIContainerInitType.Singleton);

      s6 := DIContainer.Get('srv6') as TService6;
      WriteLn(s6.ToString);
      s6 := DIContainer.Get('srv6') as TService6;
      WriteLn(s6.ToString);

      // AddComponent with QualifiedClassName, a custom initializer, an alias.
      // Component will be created as singleton (single instance managed by Container)
      DIContainer.AddComponent(DIContainerUtils.GetQualifiedClassName
          (TService7),
            function: TObject
            begin
              Result := TService7.Create(DIContainer.Get(TService1) as TService1,DIContainer.Get(TService1) as TService1);
            end,
            'srv7intf',
          TDIContainerInitType.Singleton);

      s7 := DIContainer.Get('srv7intf') as TService7;
      WriteLn(s7.ToString);
    finally
      DIContainer.Free;
    end;
  except
    on E: Exception do
      WriteLn(E.ClassName, E.Message);
  end;
  readln;
end.

DelphiDIContainer also handle constructor injection with automatic dependency resolution for service.

Enjoy and stay tuned.

My AMQP Delphi wrapper is in the standard 0MQ distribution

Yes, this is a nice news!
My AMQP Delphi wrapper for 0MQ is officially included into the distribution of 0MQ.
Now sources are managed into the main svn trunk.
You can read the news in the project’s main page.
You can see the code here.

In the upcoming greatest Delphi conference ITDevCon, I’ll have a talk about MoM (Message oriented middleware) and I’ll talk about ZeroMQ too.

Using AMQP from Delphi with ZeroMQ

The Advanced Message Queuing Protocol (AMQP) is an open standard application layer protocol for Message Oriented Middleware (MoM).

The defining features of AMQP are message orientation, queuing, routing (including point-to-point and publish-and-subscribe), reliability and security.

The good news about AMQP is that AMQP mandates the behaviour of the messaging provider and client to the extent that implementations from different vendors are truly interoperable, in the same way as SMTP, HTTP, FTP, etc. have created interoperable systems.

In a so “Open” market, live an interesting project called ZeroMQ.

In a my recent Delphi project, I must choice a thin and fast messaging system, ZeroMQ has been the choice.

However, ZeroMQ has not the Delphi client for talking with the broker, so I decided to write my own.

ZeroMQ is very fast but doesn’t support some enteprise features like users management and message persistence, but is very simple to use and to intergate in a legacy system.

For example, with my wrapper, a simple “sender” is like following:

zmq := TZeroMQ.Create;
try
zmq.Open('localhost');
ex := zmq.CreateLocalExchange('MyExchange', zmqStyleDataDistribution);
zmq.Bind('MyExchange', 'GlobalQueue');
zmq.Send(ex, 'Hello World From Delphi');
finally
zmq.Free;
end;

And a simple receiver is simple as follow:

zmq := TZeroMQ.Create;
try
zmq.Open('localhost');
ex := zmq.CreateLocalQueue('LocalQueue');
zmq.Bind('GlobalExchange', 'LocalQueue');
zmq.Receive(msg, msgtype, msgsize, zmqBlocking);
WriteLn(msg);  //we are in a console application
finally
zmq.Free;
end;

In the distribution there are a complete set of examples including a simple “Chat” application.

ZeroMQ is primarily intended to power stock trading business, this is the reason becouse is very fast.

To use ZeroMQ you need the ZeroMQ server downloadable from http://www.zeromq.org/ where you can find additional info about Exchange and Queue configuration and binding.

Wrapper (beta) can be downloaded from the ZeroMQ section.

Comments and fix for the wrapper are very apreciated.

Have fun and happy messaging :-)

My speech at “PHPCon Italia 2009”

I will talk at the italian PHPCon in Rome on March 18-20 2009.

I will talk about “Data Access Design Patterns” showing many PHP examples.

PHPCon Italia 2009
Holiday Inn Eur Parco dei Medici
Viale Castello Della Magliana 65
ROME, 00148
ITALIA
Web Site

Click here for discount on ticket (italian web site)

And this is the “Speaker Button”

My Speaker Button
My Speaker Button

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

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:

ICalculatorView = interface
  ['{471E3657-C6CE-49A3-BCB4-8FA6AF611DAD}']
  function FirstOperand: String;
  function SecondOperand: String;
  procedure SetFirstOperand(Value :String);
  procedure SetSecondOperand(Value :String);
  function GetOperator: IGUISelectableList;
  procedure SetCalcResult(const Value: String);
  procedure SetCalcResultReadOnly(const Value: Boolean);
  function Error: IGUIEdit;
end;

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

  function FirstOperand: String;
  function SecondOperand: String;
  procedure SetFirstOperand(Value :String);
  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:

  IGUIBaseInterface = interface
    ['{F0B7F031-9302-415E-8545-1FE20A365840}']
  end;

  IGUIEdit = interface(IGUIBaseInterface)
    ['{FE2D56FB-0CFB-4B33-9B56-0A523B235D37}']
    procedure SetText(const Value: String);
    function GetText: String;
    function GetAsInteger: Integer;
    function GetAsFloat: Extended;
    procedure SetReadOnly(const AValue: boolean);
    procedure SetVisible(const Value: Boolean);
    function GetTextAsInteger: Integer;
    procedure SetTextAsinteger(const Value: Integer);
    function GetTextAsFloat: Extended;
  end;

  IGUISelectableList = interface(IGUIBaseInterface)
    ['{EEFE5C52-94C3-464B-80F2-05E443B0F0F6}']
    procedure SetText(const Value: String);
    function GetText: String;
    procedure SetValue(const Value: String);
    function GetValue: String;
    function GetSelected: ISSKeyValue;
    procedure AddPair(AKey, AValue: String);
    procedure Clear;
  end;

For implementation details see attached sample code.

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

TfrmCalculatorView = class(TForm, ICalculatorView)
  //code 
end;
  //interface section
procedure TfrmCalculatorView.FormCreate(Sender: TObject);
begin
  //Link controls with related interface
  IOperators := TGUISelectableList.Create(ComboOperators);
  IError := TGUIEdit.Create(EditError);

  //link view and presenter
  //In this version VIEW know PRESENTER
  FPresenter := TCalculatorPresenter.Create(Self);
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.

procedure TfrmCalculatorView.Button1Click(Sender: TObject);
begin
  FPresenter.DoCalc;
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.