views:

412

answers:

2

My team is maintaining a huge Client Server win32 Delphi application. It is a client/server application (Thick client) that uses DevArt (SDAC) components to connect to SQL Server.

The business logic is often "trapped" in Component's event handlers, anyway with some degree of refactoring it is doable to move the business logic in common units (a big part of this work has already been done during refactoring... Maintaing legacy applications someone else wrote is very frustrating, but this is a very common job).

Now there is the request of a web interface, I have several options of course, in this question i want to focus on the VCL for the web (intraweb) option.

The idea is to use the common code (the same pas files) for both the client/server application and the web application. I heard of many people that moved legacy apps from delphi to intraweb, but here I am trying to keep the Thick client too.

The idea is to use common code, may be with some compiler directives to write specific code:

{$IFDEF CLIENTSERVER}
  {here goes the thick client specific code}
{$ELSE}
  {here goes the Intraweb specific code}
{$ENDIF}

Then another problem is the "migration plan", let's say I have 300 features and on the first release I will have only 50 of them available in the web application. How to keep track of it? I was thinking of (ab)using Delphi interfaces to handle this. For example for the User Authentication I could move all the related code in a procedure and declare an interface like:

type
  IUserAuthentication= interface['{0D57624C-CDDE-458B-A36C-436AE465B477}']
    procedure UserAuthentication;
  end;

In this way as I implement the IUserAuthentication interface in both the applications (Thick Client and Intraweb) I know that That feature has been "ported" to the web. Anyway I don't know if this approach makes sense. I made a prototype to simulate the whole process. It works for a "Hello world" application, but I wonder if it makes sense on a large application or this Interface idea is only counter-productive and can backfire.

My question is: does this approach make sense? (the Interface idea is just an extra idea, it is not so important as the common code part described above) Is it a viable option?

I understand it depends a lot of the kind of application, anyway to be generic my one is in the CRM/Accounting domain, and the number of concurrent users on a single installation is typically less than 20 with peaks of 50.

EXTRA COMMENT (UPDATE): I ask this question because since I don't have a n-tier application I see Intraweb as the unique option for having a web application that has common code with the thick client. Developing webservices from the Delphi code makes no sense in my specific case, so the alternative I have is to write the web interface using ASP.NET (duplicating the business logic), but in this case I cannot take advantage of the common code in an easy way. Yes I could use dlls maybe, but my code is not suitable for that.

+2  A: 

The most important thing that you have to remember is this:

  • Your thick client .EXE process is used by one person at a time (multiple persons will have multiple instances of that .EXE).
  • Your intraweb .EXE process will be used by many persons at a time. They all share the same instance of the process.

That means your business logic must not only be refactored out into common units, the instances of the business logic must be able to reside into memory multiple times, and not interfere.

This starts with the business logic that talks to the database: you must be able to have multiple database connections at the same time (in practice a pool of database connections work best).

In my experience, when you can refactor your business logic into datamodules, you have a good starting point to support both an Intraweb and a thick client version of your app.

You should not forget the user interface:

  • Thick clients support modal forms, and have a much richer UI
  • Web browsers support only message dialogs (and then: those are very limited), all fancy UI stuff costs a lot of development time (though for instance, TMS has some nice components for Intraweb)

Then, to top it off, you have to cope with the stateless nature of the HTTP protocol. To overcome this, you need sessions. Intraweb will take care of most of the session part.
But you need to ask yourself questions like these:

  • what should happen if a user is idle for XX minutes?
  • how much session state can I store in memory? and what if it doesn't fit?
  • what do I do with the session state that does not fit into memory?

This is just a start, so let use know when you need more info.
If it gets very specific to your app, you can always contact me directly: just google me.

--jeroen

Jeroen Pluimers
My application has some common libraries + forms and datamodules. Forms and datamodules has sometimes high coupling, so probably I'd need to remove the dependencies of the form in the datamodules, or using conditional code for managing IW and VCL.My app is quite simple from the state point of view, I think. I need to do some IW research, I will wait for some documentation for IW XI to be available. As I will start some code investigation I will consider sending you a prototype (a very simplfied version of my application and a proposed IW version so you can comment). Thanks.
Take a close look at my talk "Smarter Code with Databases and Data Aware controls" mentioned at the end of the link below. It introduces some ideas and components to make it easier to remove dependencies between forms and data modules. http://wiert.wordpress.com/2009/04/24/spoken-coderage-iii-december-1-5-2008-on-delphi-database-and-xml-related-topics/
Jeroen Pluimers
+1  A: 

I think if you move your application to n-tiers will be a better solution, it will be easier after that to be used by the desktop and web applications.

you already made the first part by decoupling the business logic from the presentation, you can use RemObject SDK or DataSnap that bundled with Delphi.

after that you will have working desktop application, and you can use Intrawebm Asp.net or what ever for web part, and in this way you will not have to duplicate the business logic again for the web part.

usually converting desktop application to web not easy as you thought, because they work in different environment, and you need to build each one as it's nature.

Mohammed Nasman
If n-tier was an option for me I would definetely go for it. But unfortunately there is too much code, already most of it in datamodules, this is why intraweb is so appealing to me. by moving code to datamodules I can easily refactor the code. n-tier is an option for a complete rewriting of the application, but the costs/benefits of this are not acceptable for my company.Thanks a lot for the reply.
That's if you need to work on ideal n-tier design, I did that with old application that needed to work with asp.net, so I exposed most needed function to another web service application that share the same code with the desktop one, and it then called by asp.net application, and now it's working like a charm great ;-).
Mohammed Nasman
Isn't having two apps sharing the same datamodules a kind of logical N-tier?
Jeroen Pluimers