Tag Archives: Delphi

TRESTRequestDataSetAdapter Example

The TRESTRequestDataSetAdapter component (introduced in RAD Studio 11.0) helps create a REST Request, from a TDataSet to send to a REST Server.

The TRESTRequestDataSetAdapter is a companion for the TRESTResponseDataSetAdapter component that takes a JSON data packet from a REST request response and concerts it into a TDataSet.

The TRESTRequestDataSetAdapter works well with the TEMSDataSetResource to accept data from POST, PUT, DELETE operations from the client side to update server side data.

This video will take you though how this works, and also demo’s a really useful unit of code, REST.DataUpdater.pas, that automatically manages the data transport based on the type of data update you have made.

Continue reading TRESTRequestDataSetAdapter Example

How to use Azure Cloud Cognitive Services?

What is Azure Cognitive Services?

According to Microsoft, the Cognitive Services in the Microsoft Azure Cloud bring AI within reach of every developer, without requiring machine learning expertise.

Using the Azure Cognitive Services API you can use API’s to embed the ability to hear, speak, translate and understand directly into your applications.

— keep reading to see how to use Azure Services with Delphi (inc Videos and code sample —

Continue reading How to use Azure Cloud Cognitive Services?

Delphi 64bit Code

Updating 32bit code to Delphi 64bit

Ever since Delphi XE2, it has been possible to generate Delphi 64bit applications from the same code base as your traditional Windows 32bit Delphi code. The business case for 64-bit for business is covered in this tech paper The Impact of 64-bit Applications to your Company’s Bottom Line.

On the whole moving to 64bit (on iOS or Windows) is beautifully simple to achieve! It can be just as simple as adding the Delphi 64bit Windows target platform in the project manager and rebuilding the project.

My experience from talking to many developers who have moved up is that normally there are a few things to check in your code but typically its not a massive task to get compiling and ready to test.

A lot has been recorded on moving from Windows 32bit to Windows 64bit Delphi and this should be a useful summary if your just planning now moving up from older versions of Delphi to Delphi 10. If you are building iOS applications, then you will need to use the 64bit build now to get into the AppStore. Thankfully, Delphi has made the task of using 64bit very simple across all platforms and protected us from the headaches non Delphi Developers have had on the whole.

Lets start with this short video from David I who covers some the foundations in 7 minutes!

Continue reading Delphi 64bit Code

Bitmap to PNG/JPEG/JPG in Delphi / C++Builder

In FireMonkey, Bitmap is the common currency for working with images. If you want to send an image via Stream using LiveBindings or want to save an Image to disk or into a database on a device with limited storage however, they are quite large.

Thankfully FireMonkey has a really easy to use CodecManager that allows you to SaveToFile or SaveToStream and convert to PNG or JPG across all platforms (which are vastly smaller in size).

SaveToFile

Creating a PNG, JPG/JPEG is as simple as calling the Bitmap.SaveToFile with the correct file extension. This works really well with even more extensions supported.

Personally I would use PNG as the JPG formats are around the same size on some test I’ve run, but produce a better quality of image, especially when grabbing screenshots.

SaveToStream and TBitmapCodecManager

Bitmap.SaveToStream doesn’t expose the CodexManager in the same way as it is available automatically with the SaveToFile option so takes a little more work to get a compressed image into the memory stream.

This is done using the TBitmapCodecManager class. A simple screen test has gone from over 1mb as a bitmap to around 6kb when saved to PNG using this approach.

The following code is an example using two image viewers (and a few save to files to help demonstrate the difference in file size). The key part is the TBitmapSurface and TBitmapCodecManager.

procedure TForm1.Button1Click(Sender: TObject);
var
  Stream: TMemoryStream;
  Surf: TBitmapSurface;
  aFile : string;
begin
  ImageViewer1.Bitmap :=
    TabControl1.MakeScreenshot;

  // Comparison save file as BMP 
  aFile := 'c:\test\myImage';
  ImageViewer1.Bitmap.SaveToFile(aFile+'.bmp');
  Stream := TMemoryStream.Create;
  try
    Stream.Position := 0;
    Surf := TBitmapSurface.Create;
    try
      Surf.Assign(ImageViewer1.Bitmap);
      // use the codec to save Surface to stream
      if not TBitmapCodecManager.SaveToStream( 
                       Stream, 
                       Surf, 
                       '.png') then
        raise EBitmapSavingFailed.Create(
              'Error saving Bitmap to png');
    finally
      Surf.Free;
    end;
    // do something with the png stream image
    Stream.Position := 0;
    ImageViewer2.Bitmap.LoadFromStream(Stream);

    // comparison output as PNG from the stream
    Stream.Position := 0;
    Stream.SaveToFile(aFile+'.png');
  finally
    Stream.Free;
  end;
end;

Now, you can obviously save as a ‘PNG’ from the bitmap, but the above code shows how to avoid saving a file  to disk unless you really need to.

Happy coding!

Setting the default XML DOM in Delphi XE7

Managing the default XML DOM

Scanning the whats new in RAD Studio XE7 (Delphi, C++ Builder) it covers the introduction of a new XML Dom (OmniXML) meaning there are now 3 XML DOMS to choose from when setting the default XML DOM.

  • MSXML
  • ADOM
  • OmniXML

The XML Dom defines which engine in essence is used to work with your XML documents.

Should I read on? Well if your using SOAP or XML in your projects, then this could make a difference to your speed and performance of the applications, and it takes seconds to implement.

Continue reading Setting the default XML DOM in Delphi XE7

Castalia IDE Plugin Free with XE7 (ends soon)

One present I’m going to be playing with over Christmas is the Castalia IDE plug in. If you want to know why, check out the 10 minute demo here of some of the cool refactoring and IDE tools that Castalia provides.

Don’t forget if your latest version is XE2 your last chance to qualify for upgrade pricing is now.  http://www.embarcadero.com/radoffer

The Embarcadero sales teams will be in between Christmas and new year so there is still time to code smarter in the new year.