Overview of the Web Broker Architecture

This overview is meant as a short introduction of a technology that has existed since Delphi 390, for those who never used it or used it only occasionally. If you already used WebBroker you can certainly skip it. The WebBroker technology, available in Delphi since the early days of the product, is a framework to let you create Web server extensions that can be deployed as CGI applications, ISAPI libraries, and (even if unofficially) Apache modules. There is a fourth option, which is the use of...

JSON and Object Marshaling

There is another new feature in Delphi 2010 that makes a huge difference in the architecture the types of parameters for server methods now include TJSONVal ue and descendant types. What is relevant here is not the ability to pass individual values (integers, strings), but the fact you can use this approach to pass complex data structures. While DataSnap still doesn't allow you to pass Delphi objects to and from server methods, what you can do is transform Delphi objects into an equivalent JSON...

The Data Snap Web Broker Wizard

Creating DataSnap applications based on the WebBroker architecture is reasonably simple thanks to another new Wizard added to the Delphi 2010 IDE, the DataSnap WebBroker Application wizard. Differently from the DataSnap Application Wizard, this one won't let you pick a TCP IP connection and offers you the application types supported by WebBroker as options, rather than the development of full-blown, console, or service applications. You can see the Wizard form in the next page. To build an...

Finally

The code for MS SAX support worked with basically no changes, as my original code used the VBSAX interfaces obtained by importing the type library (probably of MS XML version 4 at the time). All I had to do was change the name of the Set_documentLocator method to _Set_documentLocator, adding the initial underscore. For the code in the ADOM XML I didn't find any equivalent to the original SAX-like support, so I basically had to rewrite that using the new signals-based coding style. The core of...

Returning Multiple Results

As mentioned earlier, the JSON result returned by the DataSnap REST support is invariably an array. This is necessary because as you can have multiple input parameters you can also have multiple output values, just use parameters passed by reference (var) or output parameters (out). 115 The result is returned in a JSON array structure as in more complex situations you might have further parameters passed by reference that the server method returns along with its result. I'll cover this in a...

End

74 According to Microsoft's SDK documentation for the data structure at To manage and interpret the x and y coordinates, you might want to call the PhysicalToLogical Point Windows API function to convert the physical screen location to the logical coordinates the application understands. To receive this information, as mentioned, you need to have multi-touch enabled hardware, but the application must also register individual windows to receive touch messages by calling the RegisterTouchWindow...

The Standard Gestures

In the previous example we have enabled all of the standard gestures to the form and the panel, but so far I haven't given you any indication of which of these are predefined gestures. You can find a complete list with a graphical representation of each gesture in the help page Here I've listed all of the standard gestures logically grouped (the grouping is mine), providing only a few of those images Gestures with a single movement Left, Right, Up, and Down. Gestures with two perpendicular...

Touch Hardware

You might think that touch hardware comes in the form of touch screens you add to your existing PC. This is hardly the case, although some multi-touch monitors are starting to appear. In most current offers, touch screens are part of a single computing device, either a touch screen laptop computer or an all-in-one desktop (or wall-mounted) device. Here I won't provide a complete overview of touch-enabled hardware, but focus only on Windows 7 enabled devices62. These includes portable computers...

Chapter Touch And Gestures

With mouses and keyboards being part of the computers landscape since the Nineties, experimental user interfaces have been focused mostly on script recognition (starting with the Apple Newton, the Graffiti input system of Palm hand computers, and including tablet PC support in Windows) and voice recognition. These experiments have never reached a critical mass or affected everyday computer users. Over the last couple of years, however, a slow revolution has started outside of the PC realm. The...

Property Editors for Actions and Dates

Beside the changes in VCL components, Delphi 2010 has a couple of very interesting additions in terms of changes to property editors, which spawn across multiple components. Every time you have a TDate property, you can now use a MonthCalendar to pick a value at design time MonthCalendarl rMonthCalendar Properties Events I_ MaxSelectRange 31 MinDate Multiseli Name Pareri Parente Pareli tD Paren tF( ParentSI PopupMi ShowHin Shu' .'Tui A much more useful update was made to the editor of the...

Initialization

TPicture.RegisterFileFormat( 'jpeg', sJPEGImageFile, TJPEGImage) Tpicture.RegisterFileFormat( 'jpg', sJPEGImageFile, TJPEGImage) This means that in Delphi 2010, when running on a version of Windows with WIC support, you can manage the JPG files using this last component. All you have to do is to declare the following TPicture.RegisterFileFormat ('jpg', 'JPEG Image', TWICImage) This is code you'll find in the TiffViewer example, which let's you open in an Image component a TIFF or a JPEG file in...

Build All and Active Project

There is another significant change (which I don't like really) in the way the project manager behaves when building multiple projects. What used to happen when doing a Build All was that each project would become the active project in turn and you could use this visual clue to see the progress of a long compilation. Now you get information about each project while it compiles, but no overall view. Another difference, and possibly the reason for this change, is that at the end of the...

Indy Http Eexternalexception

ADO Alexey Allen Alternative Document Object Model 256 Andreano anonymous Background Bamboo Barry Berry Borland Database Engine 206 Build Cary Chris Bensen 9, 158, 184, 186, 188, 190 Chris Class class ClientDataSet 37, 180p., 227, 257, 277 Code Code compiler Component Editor Pane 37 Component conflicting CPU Ctrl + Custom Daniel Data DataSnap 211, 214, 216, 218, 221, 223, 228, DataSnap Filters Compendium 232 208 DBGrid 157, 179pp., 202, 204, 227 Debug Debugger Delayed Delphi 2007 Handbook 6,...

Many More Recent Files

Delphi Programming Properties

In Delphi the lists of recent projects and files have always been limited to a fixed size, 5 for projects and 10 for files (units). Now in the File Reopen menu you can pick the Properties command and open up a configuration dialog box, which lets you both change that number and and clean up the list, by removing non-existing files and individual entries you don't care about Although this is a nice addition, I think I'd still prefer using the project management features of the Welcome page,...

The Return of the Component Toolbar

In Delphi 2010 there is now an option to display the components visible in the Tool Palette in a toolbar below the main menu12. This is extremely similar to how the Component Toolbar used to look like in Delphi 7 and before), and the feature has been specifically added as a way to convince some of the Delphi 7 aficionados to migrate to a new version File Edit Search View Refactor Project Run Component Tools Window Help MEE 3 iSffSiB -BISfflfi i - Il E i V - + - Standard System Additional Win32...

Table Of Contents

My Delphi Handbook The Delphi 2010 Editor and Tech Contact Table of Chapter 1 A Better Proxy Installation First IDE Filter Wild Advanced Customizing IDE The Delphi 2010 The Search Searching with Directory The Code Live Templates and Code The Project Build All and Active The Object The Description The Component Editor Other IDE Background The Return of the Component Many More Recent Use Unit Updates to the View What's Chapter 2 The Dragging the Instruction Small UI Debugging Debugger Advanced...

Calling the REST Server From a jQuery Client

If all you need is to pass object data from a server side Delphi application to another one, there could be many alternatives to using JSON. This choice makes a lot of sense when you want to call the Delphi compiled server from a JavaScript application running in the browser. This case is quite relevant because AJAX (Asynchronous JavaScript calls done in the Web browser) was and still is one of the driving forces behind the adoption of REST. Calling a corresponding SOAP server from a Browser...

Building a Value Replacer for UCSChar

Before we delve into the development of a debugger visualizer, let me point you to a specific situation in which the debugger provides limited information about the values of a type. Consider the following code snippet, which is part of the DebugVisual example which is also used to demonstrate the other debugger visualizers. procedure TForm39.btnUcs4CharClick Sender TObject var ShowMessage Character.ConvertFromUtf32 ch end If you put a breakpoint in the code above and look to the value of ch,...

HTTP Client and Server

The HyperText Transfer Protocol is the standard at the heart of the World Wide Web, and needs no introduction. Granted, HTTP can be used by Web Browsers, but also by any other application. In Delphi applications the simplest way to write a client application that uses HTTP is to rely on the Indy HTTP client component, or IdHttp. If you call the Get method of this component, providing a URL as parameter, you can retrieve the content of any Web page and many REST servers105. At times, you might...

Processing the RSS Data with XPath

To extract the relevant information from this XML document the RssClient program uses XPath expressions. For example it reads the title of the first blog post item of the list uses the expression rss channel item 1 tit1e. 106 A video of the development of this Delphi client application step-by-step and its final result is available on YouTube at and in my blog at This is done in a cycle along with the extraction of some other information, formatted and displayed in a list box. Using XPath...

Web Service Technologies SOAP vs REST

The idea of a web service is rather abstract. When it comes to technologies, there are currently two main solutions that are attracting developers. One is the use of the SOAP standard Simple Object Access Protocol, see the reference site at http www.w3 .org TR soap , another is the use of a REST Representational State Transfer approach, along with its variation XML-RPC XMLRemote Procedure Call . What is relevant to notice is that both solutions generally use HTTP as the transmission protocol...

Testing the Connection in Data Explorer

It is interesting to notice that in the Data Explorer window of the Delphi 2010 IDE you can configure and test the client connection quite easily. It is actually easier to test the connection in this pane than setting up an SQLConnection component manually. To try this out, simply run the server possibly as a stand alone application using the Run Without Debugging command , move to the Data Explorer, pick the DataSnap driver, and add a new connection. Now open the connection configuration and...

Multi Touch Support

As I detailed in the section From Single Touch to Multi-Touch, Windows 7 and Delphi 2010 have specific support for multi-touch hardware, basically in the form of a new Windows message wm_touch and support for handling it at the VCL level. Considering the current limited crop of multi-touch enabled hardware, though, this support should probably be restricted to specific applications for quite some time. This is why the coverage of native touch, or wm_touch, in this chapter is restricted to this...

Google Geocoding Service

The first service of this category I'm going to use is Google's Geocoding service, which lets you submit an address and retrieve its latitude and longitude q address amp output format amp key key You can also type a similar URL in your browser for testing purposes, as you can see here showing New York coordinates in a browser in XML format lt krul xraln3 ,'Iittp earth. google . cora kml 2 . 0XRe3ponse gt lt name gt New York, EJS lt name gt lt Stacus gt lt addxess gt New York, NY, USA lt addxess...

Larger Executable Files

The obvious effect of adding Extended RTTI information to an executable file is that the file will grow larger which has the main drawback of a larger file to distribute, as the extra loading time and memory footprint would be almost unnoticeable . For very small programs, the effect is somewhat minimal, but in large applications the increase will be significant. I'll look at very small programs first, testing two applications I've used over the years and with multiple versions of Delphi, to...

Returning a List of Customers

The server action returning a list is called with the customers URL. In its server code, the application scans the data set and returns an XML structure with the company name and the customer ID for each customer record. With the URL You'll see an XML result like lt customers gt lt customer gt lt id gt 1221 lt id gt lt Company gt Kauai Dive Shoppe lt Company gt lt customer gt lt customer gt lt id gt 1231 lt id gt lt Company gt Unisco lt Company gt lt customer gt This XML code is generated using...

For I to do begin

D2D1MakeRotateMatrix I 6, D2D1PointF 50, 50 , matrix - I 0.1 d2dCanvas.TextOut 200, 100, strText end There is a little more code to get the original transformation matrix and reassign it at the end, but the three code snippets just displayed sum up the code of the OnPaint event handler of this example. For another example of Direct2D in Delphi, you can refer to the following post by Pawel Glowacki, who translated one of the Microsoft SDK demos the Advanced Path Geometries Demo in Delphi

Accessing the REST Server with a Browser

We can test this server to see if it works. After compiling and running the program, remember to run the Web App Debugger available in Delphi's Tools menu , and start it using the corresponding button. The Web App Debugger runs on a specific port, by default 8081, so the URL will start with http localhost 8081 Next in the URL comes the application name and the Web App Debugger class name which in this case are identical , separated by a period If you open the combined URL in a Web browser you...

Data Snap HTTP Server with the Wizard

For that first demo I've taken an existing DataSnap application and moved it from a TCP IP connection to an HTTP connection. It is even easier to create a new application with the DataSnap Wizard and ask for either or both connectivity options. If you select the DataSnap Server in the DataSnap page of the New Item dialog box or Object Repository you'll get the following options You can pick three different application architectures, one or both communication protocols optionally asking for HTTP...

Basic Gesture Example

Rather than describing the complete VCL gesturing architecture in theory, let us start by building a very simple first example I've called Gesturesoi. The program has a form with a panel and a memo control, plus the GestureManager component. This last component doesn't have specific setting, as its editor let's you add custom gestures to it, something we will focus on later. The management of gestures takes place in the Touch property of the target control, for example the form. This property...

Themes Support and Other DBGrid Extensions

Even with the stronger themes support already in the VCL for a couple of versions introduced in Delphi 7, but much expanded in Delphi 2007 , not all of the visual controls got full themes support. A notable absence was in the VCL grids, both the plain ones StringGrid and DrawGrid and the data-aware version DBGrid . This has now been addressed. In the image on the side you can see the same application DbxMulti2010, the new version of a simple dbExpress demo I used in previous books with and...

Direct Write

We have seen that we can use the basic text drawing functions of Direct2D most like the GDI ones, but support for the precise display of text has much improved compared to the past. The new interfaces for managing font families, text layouts, text formats, and the like are collectively known as DirectWrite. In Delphi you can access to the various DirectWrite objects using the factory object returned by the DWriteFactory global function of the Direct2D unit which creates and initializes a...

Using JSON Converters and Reverters

The JSON marshaling support works great for basic types, but when data structures become complex, you might want to customize the actual information that is saved. This is possible thanks to the ability of installing custom converters and reverters which you can register for given classes and fields. The converters and reverters are implemented using anonymous methods98. Suppose, as an example taken from the same JsonMarshal demo, that you have a class like the following type theName String...

TSQLTime StampOffset Field TBinary Field TBytes Field

TVarBytesField TBlobField TMemoField TWideMemoField widestring memo TGraphicField TObjectField TADTField Abstract Data Type TArrayField TDataSetField TReferenceField TVariantField TInterfaceField There are some other changes focused on very specific needs, like local dependent string formatting for date and time functions, the remapping of 64-bit integers to the Int64 rather than BCD, and other similar changes probably not worth covering in detail.

Building a Database Oriented REST Server

If the original idea behind DataSnap focused on moving data tables from a middle-tier server to a client application, it might be quite odd at first to realize that you cannot return a dataset from a REST server written in Delphi 2010. Well, you cannot return it directly or as easily as you return its XML representation, but you can create a JSON result with all of the data of a Delphi dataset. That's the focus my last example. The program is quite bare bones, as all it does is return the data...

Rtti Objects Lifetime Management and the TRtti Context record

If you look at the source code of the btnTypesListClick method listed earlier, there is something that looks quite wrong. The GetTypes call returns an array of types, but the code doesn't free these internal objects. The reason is that the TRttiContext record structure becomes the effective of owner for all of the Rtti objects that are being created. When the record is disposed that is, when it goes out of scope , an internal interface is cleared invoking its own destructor that clears all of...

Editing Data with jQuery

Now that we have the CRUD operations available on the REST server, we can complete our JavaScript client application with the code of the three editing buttons the image of the browser-based user interface was shown earlier . While jQuery has specific support for the get operation with different versions, including the JSON-specific one we have used earlier and some support for post operations, for the other HTTP methods you have to use the lower level and slightly more complex .ajax call. This...

Notable Differences Between Vista and Windows

Having covered in summary new features of recent version of Delphi that let you better support Windows Vista and Windows 7, I have to underline the fact that Windows 7 adds a few extra features that make existing old Delphi applications more compatible with the new operating system. There are a couple of these differences worth mentioning. The first relates with the preview of the application main form available in Windows Flip the task bar preview , Windows Flip 3D, or even the plain list of...

Returning the XML Data of a Client DataSet

The second action, actionCustData, is the simplest to implement, on both the server and client side. All it does is return the entire data content of a ClientDataSet component, using its XML representation. The server simply returns that XML procedure TWebModule3.actionCustDataAction Sender TObject Request TWebRequest Response TWebResponse var Handled Boolean begin Response.Content cdsCustomers.XMLData Response.ContentType 'text xml' end Using the corresponding URL you can see the entire XML...

Handling wmtouch

The wm_touch message is a raw, low-level Windows message, providing a significant amount of information about the user input unlike a mouse message . Considering the limited data a Windows message can carry, this is actually not a precise description. 73 Chris is a Delphi R amp D member who worked on touch support in Delphi 2010. His blog is at http chrisbensen.blogspot.com . I got permission from him to quote the source code of this demo application in my book. What you receive in the...

Touch Keyboard

Keyboard Special Purpose Keys

When you are creating applications for kiosks and other devices which don't have a keyboard attached, it is nice to show one on screen and let users type by selecting these keys with their input device possibly their finger, as using a virtual keyboard with the mouse is far from a nice experience . The VCL in Delphi 2010 includes a framework for creating virtual keyboards, based on the new TouchKeyboard component and the two related units, Keyboard and KeyboardTypes. If you drop the...

The Gesture Manager of the VCL

In Delphi 2010 the VCL adds to its core features a gesture management architecture. This is built into the TControl hierarchy, with the new OnGesture event surfacing in all visual components. However, the actual gesture management code can be selectively compiled into the VCL or not, thus avoiding the extra overhead63 in case you are not interested in using gestures support. The core class of this architecture is the new GestureManager component. It can be used to handle gestures performed with...

Midas DLL Now With Source

A significant change behind the scenes in Delphi 2010 is the availability of the source code of midas.dll. This library, which is either deployed along with your application or compiled into the Midaslib unit and bound to your executable, is the engine behind the ClientDataSet component. In fact, even if there is the full Delphi source code of this component, its actual data processing code is inside the DLL, that the component invokes frequently. It happened over the last few years that...

Google Translate API

Another simple and interesting example of a REST API provided by Google is their translation service, called Google Translate REST API. The documentation is at In this case there is no need for a signup key and an INI file , but only provide a referrer site although everything seems to work even without that information . You can ask for a translation in your Web Browser by entering an URL like The output of this call is visible above I have also listed the JSON result for trans1atedText Was f...

Chris Bensens Touch Move Demo

To demonstrate touch support in Delphi 2010, along with Direct2D support that I covered in the last chapter and inertia manipulations that I'll cover in the next section , Chris Bensen wrote a very nice demo called TouchMove, which I decided to refer to in this section. I won't cover other elements of the demo, only how it manages touch76. The demo handles a number of touch points at the same time, creating for each a glow spot element or using an existing one if the touch operation was...

Client for the Web Server

Now that we have built a DataSnap server deployed as a web server extension, we have to change a few things in how a client application refers to it. The SQL- Connection component, in fact, won't refer to the server using host name and port, but using the server base URL object SQLConnection1 TSQLConnection DriverName 'Datasnap' LoginPrompt False Params.Strings 'DSnapWebAppDebug.dsnap1http' 'CommunicationProtocol httpr

Using the Windows Imaging Component

Another new graphic-related feature of the VCL is its support for the Windows Imaging Component WIC . This is a Microsoft framework for working with images and their metadata, which supports several image formats and can be extended with new image formats by software and hardware vendors like digital camera makers . Not only can the WIC can display images, but it has also a lot of image processing capabilities built into it and independent from the actual image format. The WIC is available in...

Calling the REST Server from a VCL Client

Now that we have built the server and made sure that it works, we can write a Delphi client application to test it. We can use two different approaches. One is to fall back to write a Delphi DataSnap client, using the specific transport layer provided by REST. But it won't make a lot of difference compared to using the HTTP or TCP transport layers of DataSnap. The second option, which is the one I'm going to follow, is to create a custom REST client just like all of the various clients I built...

The Code Formatter

Many Delphi developers have long relied on third-party source code formatters to clean up the layout of existing code and promote company standards. Even if late to the game, Delphi itself now includes code formatting capabilities, with enough flexibility built into the system to make it worthwhile even in what is clearly a first attempt, but still a good one . The Code Formatter is invoked with the Format Source command of the local menu of the editor or with the corresponding Ctrl Alt F...

Working with Taskbar Buttons in Windows

One of the most noticeable new features of the Windows 7 user interface is the new role of taskbar buttons, the graphic generally positioned at the bottom of the screen and showing the various applications that are currently running. In Windows 7 you can mix running applications with regularly used ones You pin a program to the taskbar and its icon will remain there even when the application is not running. These new taskbar buttons provide several ways to interact with an application. When the...

New API Header Units

Several new RTL units have been added to Delphi 2010 to provide the Pascal language translation of the header files of new libraries of the Windows SDK. These new libraries include DirectX support and several others. Although I don't have room to delve into them in detail, here is a partial list of the new API header units, partially coming from third parties and available with the MPL open-source license and partially introduced by the Delphi R amp D team for the new version of the product...

Begin

Xm1w.WriteStartElement 'customer xm1w.WriteStartElement id xm1w.WriteString cdsCustomers CustNc xmlw.WriteEndElement xm1w.WriteStartElement Company xm1w.WriteString cdsCustomers 'company' xmlw.WriteEndElement xmlw.WriteEndElement cdsCustomers.Next end Response.Content sw.ToString Response.ContentType text xml finally The last action returns data for a specific customer, an individual record. The Pathlnfo for this last action is different from the others. Rather than indicating a specific URL,...

Debugger Visualizers

Another useful change in the architecture of the Delphi debugger is the ability to plug in specific visualizers for complex data structures. For example in the past when looking at a TDateTime variable, you'd see its internal floating point value. In Delphi 2010, instead, one of the pre-installed visualizers lets you see the date and time value in a specific and more meaningful way. This is quite obvious if you compare the Delphi 2009 view of a local TDateTime variable on the left with the...

Input Language and Language Libraries

In Delphi 2010 there have been a couple of significant changes for developers who build international applications. The first is that the Windows wm_InputLangChange message now triggers an internal component message, cm_InputLangChange, which is broadcasted to all windowed controls. You can intercept and process this message in a TWinCont rol descendant, by adding a procedure CMInputLangChange var Message TMessage message cm_inputlangchange 57 The new Action property editor was first mentioned...

DBGrid Inplace Editor Issues

The problem with any version of the DrawingStyle property is that as the DBGrid displays the in-place editor, it draws a thick black border around it. In effect, that's not a black border but the window background color, which is managed in a different way from the past. You can see the effect in the image here on the right. How can we fix the problem82 The issue is rooted deep in the internal painting code, which is extremely complex. There wasn't a single specific fix that caused this...

JSON Values and Marshaling in Data Snap Server Methods

Now that we know how to create a JSON value for different types and convert this representation to and from Delphi objects, we can apply it to a DataSnap server, defining methods that receive or return JSON-based parameters and Delphi objects using marshaling . The Server and the Client Applications The server class used by this example a TCP IP based DataSnap server targeting a TPersistent class and called DSnapJson is the following type METHODINFO ON TDSnapJsonMethods class TPersistent public...

TMyData class private

TheName String theValue Integer public constructor Create const aName string function ToString string override property Value Integer read theValue write theValue end We can now write some code to create an object of this class, create the mar- shaller, marshal it to a TJSONValue, and add the result to a Memo control theData TMyData.Create 'john' theData.Value 99 jMarshal jValue jMarshal.Marshal theData Memol.Lines.Text jValue.ToString In the actual code this takes place within three nested...

The SQL Server Driver

The Microsoft SQL Server driver has been updated, specifically to support MS SQL Server 2008, but this also implies an architectural change. While in the past the driver relied on the OLDDB driver installed along with the MS Data Access Components, or MSDAC , the new driver uses the native client. The Microsoft SQL Server 2008 Native Client can be freely downloaded from the Microsoft web site as part of the Microsoft SQL Server 2008 Feature Pack, August 2008 or individually in the same page...

Database Gestures

In trying to build a practical example of the use of gestures, I've decided to create a simple database application based on a DBGrid. My goal is to let users perform simple gestures like up, down, left, and right to move around the data set performing the first, last, previous, and next actions, respectively . 69 Again, it is very difficult to show the behavior of such an interactive application in an image a video for this project is available on the book web site. First, I created a simple...

Type

The attribute values, passed to its constructor, must be constant expressions, as they are resolved at compile time. That's why you are limited to just a few data types ordinal values, strings, sets, and class references. On the positive side, you can have multiple overloaded constructors with different parameters. Notice you can apply multiple attributes to the same symbol, as I've done in the RttiAttrib example, which summarizes the code snippets of this section type Simp1e Va1ue 22 TMyClass...

From Single Touch to Multi Touch

Touch screens have been around for several years now and have been popular in kiosk applications, vertical-market tasks like restaurant ordering systems, and to a more limited extent in tablet PCs. The classic touch screen can intercept the position of your finger on the surface, but returns only one given coordinate. This makes it quite a rough approximation of the position as your finger, unlike a dedicated pen with a more fine tip, will generally touch multiple screen pixels at a time60. In...

Delayed Loading of DLL Functions

In the Windows operating system, there are two ways to invoke an API function of the Windows SDK or any other DLL you can let the application loader resolve all references to external functions or you can write specific code that looks for a function and executes it if available. The former code is easier to write, as all you need is the external function declaration, but if the library or even just one of the functions you want to call is not available a frequent case if your program has to...

DirectD

The native VCL support for Direct2D is based on an abstraction of the existing TCanvas class. The Graphics unit defines a new base class, called TCustomCanvas, from which TCanvas now inherits along with the new TDi rect2DCanvas class which in turn is defined in the new Direct2D unit . For compatibility purposes, most of the existing methods of TCanvas also still work with the new Direct2D class. There are a few extra methods, but you access most of the specific Direct2D features by using the...

Using Zlib Compression

Let me start by showing you how to use the only filter94 the ships with Delphi, the compression filter. First, I've built a sample DataSnap WebBroker server, using the Web App Debugger support, and built a corresponding client. They can be found in the DSnapFilterDemo folder. The reason for picking the Web App Debugger is you can easily monitor the HTTP data. For example, the response of the method call passing the string 'This is my name' looks like HTTP 1.1 200 200 OK Connection close...

Building a REST Server

Now that we have spent a considerable amount of time looking at a few REST client applications written in Delphi, facing different permission requests and using different data type formats, we are ready to start delving into the second part of this chapter, focused on writing REST servers in Delphi 2010. Just as building a REST client is more straightforward and requires less support from developer tools than building a SOAP client, the same can be said for the server. It is true that a SOAP...

First Impressions

When you first start Delphi 2010, you won't see lots of big differences from Delphi 2009, but cleaner graphics, with new icons for the IDE and for your applications, by default. The new icon and style borrows heavily from the company style, but also revamps some of the classic elements of Delphi, like the three-column temple and the Greek helmet shown up here . Needless to say you might like the new style or not, as it is mostly a matter of taste. I think it is a good step in the right...

Streaming Objects to JSON

Now if it is this easy to create a TJSONObject and add data to it, it would be very nice to create the JSON representation of any Delphi object. This is possible in Delphi 2010 thanks to the JSON marshaling and de-marshaling support that is defined in the DBXJSONReflect unit. This unit defines an open and extensible marshaling architecture, and provides a specific implementation based on the internal TJSONConverter class. So, by default, you create a JSON marshaller by passing the JSON...

Custom Gestures

Although the list of predefined gestures is quite rich, there might be specific mouse movements that make sense for your application and for specific actions you want users to perform. In this cases, you can add custom gestures to the GestureManager component. Even if you don't plan on adding custom gestures to your application, it is worth looking at the details of this process, as it explains you what matching a gesture exactly means and which parameters you can fine-tune to improve matching....

Else

D2dCanvas TDirect2DCanvas.Create Handle d2dCanvas.BeginDraw as in previous listing Depending on which of the TDi rect2DCanvas you call, the VCL will initialize the underlying ID2D1HwndRenderTarget interface in different ways. If you pass the Canvas or the Handle to the Canvas device context and an rectangular area, Delphi will call the CreateDCRenderTarget function that let's you merge Direct2D and GDI calls over the same output surface. If you pass the form Handle, instead, the VCL ends up...

HTTP Authentication

In this application I asked the Wizard to add support for HTTP authentication, but haven't actually used it so far. What you have to do is handle the HTTPAuthenticate event of the DSHTTPServiceAuthenticationManager component. In this event handler you receive the user name and the password, but also more information about the incoming request so you could have a different authentication strategy depending on the request . In this very simple case I've used the simplest possible implementation,...

The Project Manager

There are enough small changes in the Project Manager to devote a small section to it. Being one of the most commonly used panes of the IDE, even minor changes in it become significant. Before we look into this, let me underline that project files the new .dproj format used by MSBUILD and introduced in Delphi 2007 remain identical to Delphi 2009, to the point that they even carry the same version number 12.0. The actual version number of Delphi 2010, in fact, is 149. This is a snippet of the...

WIC Transformations

Again, there is very little you have to do to use TIFF support just open a file in the Image component. However, it is important to notice that there are two sides to the WIC. One is loading and saving files with given formats. The second side is the ability to process the images. To accomplish this you have to access to the iwicimagingFactory interface, available through the ImagingFactory property of the TWICImage class. This COM factory lets you create specific COM objects that expose given...

Info

The AJAX call to MyData passes the object name as a further URL parameter and extracts from the result array the property pair called Value, showing it in an empty span HTML element. Something similar but somewhat more complex happens for the list. Again, there is an AJAX call, but this time we have to build the resulting HTML. The operation is performed in a separate refreshList function called both automatically at start-up and manually by the user lt a href lt span .getJSON baseUr1 list,...

Delphi Support for Windows Vista

Starting with Delphi 2007, the Delphi R amp D team has been putting considerable effort into supporting new versions of the operating system in the VCL. This is a change from the past, as in the name of compatibility with older versions of the operating system, Delphi 2006 still didn't provide explicit support for many features of Windows XP like new control styles. Needless to say that in some cases taking advantage of new features of Vista might mean that your application will not run as...

Overview of Data Snap in Delphi

Originally based on a COM architecture, in Delphi 2009 the DataSnap framework was rewritten in terms of connectivity now based on native sockets and overall architecture, removing all dependencies from COM. On the server side, in Delphi 2009 you could use three components87 DSServer, the main server configuration component, which is needed to wire all the other DataSnap components together. DSServerClass, a component needed for each class you want to expose. This component is not the class you...

End finally

D2dCanvas.EndDraw d2dCanvas.Free end end The TDi rect2DCanvas object is created passing the GDI canvas as parameter, which is only one of the available options as I ll cover next. You can keep that object around or create a new one each time. What it important, though, is that all output operations take place between the BeginDraw and EndDraw calls52. The program draws a series of concentric circles, using the Ellipse method, changing each time the opacity or transparency of the brush, which...

Creating Custom Filters

To add a custom filter to the DataSnap connection layer, what you have to do is Create a package featuring a transport filter class that inherits from the TTransportFilter class Implement the Processlnput and ProcessOutput virtual methods of this class Register the transport filter and install the package with the filter in the Delphi IDE. The DSnapFilterDemo folder contains the DSnapFilter01 package with a trivial MIME encoding filter. The class of the filter is defined as uses TMimeFilter...