Sessions and Threading with a Non Database Data Snap Server

If using the IAppServer interface directly is going to be the most common way for using DataSnap 2009, it is not only possible to use this multi-tier technology for remote method invocation outside of the database context. You can also use the same technology to access database data or perform database operations without using the IAppServer interface, which is fine if all you want to do is read data from the server. If you want to let the client application modify the data and post it back to the server, using custom methods could become tedious compared to the ready-to-use IAppServer interface, implemented by the ClientDataSet and the DataSetProvider components.

In any case, in this second example, I want to create a minimal server exposing a couple of simple classes. In the following sections I'll use this simple server to explore a couple of relevant issues, like server memory management and server (and client) threading.

The first server class (with two methods) I want to publish in the Dsnap-MethodServer project is the following:

{$MethodInfo ON} type

TSimpleServerClass = class(TPersistent) publ ic function Echo (const Text: string): string; function SlowPrime (MaxValue: Integer): Integer; end;

{$MethodInfo OFF}

The code of the first method simply echoes the input, repeating its last part, while the second method performs the most classic slow computation of my books (already used in the ParallelFor example of Chapter 6, among others). This is the code of the two methods:

function TSimpleServerClass.Echo(

const Text: string): string; begi n

Copy (Text, 2, maxint) + '...' + Copy (Text, Length (Text) - 1, 2);

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment