Friday, 20 August 2010

Delphi XE preview videos

Here you can see the latest videos from embarcadero talking about the new version of Delphi called Delphi XE.
First preview:
this second preview covers some of the third party tools that will be part of Delphi XE:

  • FinalBuilder, used to manage the build process
  • The ability to invoke IDE operations (like audits, metrics, code formatting) from the command line, and so invoke them from external tools like FinalBuilder
  • The integrated version of profiling tool AQTime
  • The logging support provided by CodeSite, a nice tool written by Ray Konopka.

Thursday, 19 August 2010

TBookMark problem with Delphi 2010 and TList

Going on with the big rewrite of code from Delphi 2007 to 2010 (most of it an adaptation more than a rewrite), but we've found some hidden problems as a result of changes appeared in the new version. One of the flaws was shown while I was working with TBookMark class, trying to position a dataset in a given bookmark. With the help of the Embarcadero Forum, we achieved a solution by using "generics" (I'm preparing a post with generics in Delphi 2010) because the TBookMark is now of type TBytes.
Then, the solution would be something similar to this:
uses
    Generics.Collections;

var
    bookmarkList: TList<TBookmark>; //The same as TList<SysUtils.TBytes>

//Adding the bookmark
bookmarkList.Add(cds.GetBookmark);

//We don't need the TBookMark cast
procedure TForm1.GotoBkMarksClick(Sender: TObject);
var
    Cnt: Integer;
begin
    for Cnt := 0 to Pred(BookmarkList.Count) do
    begin
        if DataSet.BookmarkValid(BookmarkList[Cnt]) then
        begin
            DataSet.GotoBookmark(BookmarkList[Cnt]);
            ShowMessage(DataSet.FieldByName('Id').AsString);
       end;
    end;
end;
You need to take into account that every project is different and the use of the TBookMark can differ from one project to another.

Wednesday, 18 August 2010

TIniFile looses unicode characters

We've recently started converting code from Delphi 2007 to Delphi 2010 and we noticed that the TInifile looses unicode characters when we try to save an unicode string into the file. The file is UTF-8 encoding and when we try to save characters like 'ó', 'ç', 'á', etc., they don't appear or some unrecognised characters are shown into the ini file instead of the normal ones.
If the file is ANSI encoded and we try yo use the Tinifile, it will work fine with the unicode characters but not if the ini file is converted to UTF-8.
To solve this, we can use the TMemIniFile class. TMemInifile has an overload for the constructor that allows you to pass the encoding used for the file. The code example to solve this is the following:
procedure TForm1.Button1Click(Sender: TObject);
var
    inifile : TMemIniFile;
    desc : string;
    temp : WideString;
begin
   inifile := TMemIniFile.Create('C:\fileIni.ini', TEncoding.UTF8);
   temp := 'óáç';
   desc := string(temp);
   inifile.WriteString('Section', desc, 'S');
   inifile.UpdateFile;
   inifile.Free;
end;

Tuesday, 17 August 2010

Reading the Exif and IPTC information from a JPEG image with Delphi

Most of you know about my passion with photography and these days I've been working on a new project setting up my own photographic web gallery. I know that I've been more focused on photography than programming, but it's one of my hobbies and after doing some courses I can say that I really enjoy it!. Anyway, going on with my passion, I started the gallery with Flash and XML, and the big problem here was the modification of all the pictures. This tedious task let me build a set of applications to increase speed and productivity while I was uploading the pictures into the web. I started creating Thundax Batch Watermark, a very powerful tool that let you add a watermark to your pictures. Then, few days ago, I released the Thundax Image Resizer to built the resized image with its thumbnail, and finally the Thundax Exif Information to obtain all the Exif (Exchangeable image file format) information contained into the picture with all the information about the camera, exposure time, focal length, etc.
This information is contained into the Resume section of the file:

And I've been struggling in how to get that with Delphi. After a few hours of research, I found the CCR Exif Library for Delphi, a very simple and powerful library for reading Exif and IPTC information. Now with my application we can get the most important information and use it to publish your work:
The library is very easy to use and with a very little lines of code we can extract all the information we want and present it in the desired format.
The code looks like this:
procedure TForm1.ListView1Click(Sender: TObject);
var
  ExifData: TExifData;
  JPEGFile : string;
begin
    if ListView1.ItemIndex = -1 then
        Exit;
    ExifData := nil;
    imgThumbnail.Picture.Assign(nil);
    Memo1.Clear;
    JPEGFile := ListView1.Items[ListView1.ItemIndex].Caption;
    try
        ExifData := TExifData.Create;
        ExifData.EnsureEnumsInRange := False; 
        ExifData.LoadFromJPEG(JPEGFile);
        if ExifData.Empty then
            Memo1.lines.Add('No Exif metadata found')
        else
            LoadStandardValues(ExifData);

      if imgThumbnail.Picture.Graphic <> nil then
      begin
        grpThumbnail.Width := (grpThumbnail.Width - imgThumbnail.Width) +
          imgThumbnail.Picture.Width;
        grpThumbnail.Visible := True;
      end;
    finally
        ExifData.Free;
    end;
end;

Now we can publish our pictures with all the camera information like this:

Camera model: PENTAX K10D       

Date/time: 03/01/2009 17:55:05

Resolution: 72 x 72 inches

Exposure time: 0,3 seconds

F number: F/4

Focal length: 28,13 mm

ISO speed rating(s): 400


You can find more information about this in the following links: