TMS Day Meerbusch Nov 23, 2017

I’m happy to announce that TMS Software organizes a new training day on Thursday November 23rd in Meerbusch, NRW, Germany.

The sessions will be spent on Google Maps integration, TMS VCL & FNC components brought by ir. Bruno Fierens, TMS CTO & Embarcadero MVP, Dr. Holger Flick, TMS Evangelist & Embarcadero MVP and myself.

If you are using TMS components or plan to use them, don’t hesitate to participate in the TMS Day. We will show some great new stuff.

Posted in C++-Builder, Delphi, FireMonkey, RAD Studio 10 Seattle, RAD Studio 10.1 Berlin, RAD Studio 10.2 Tokyo, RAD Studio XE5, RAD Studio XE6, RAD Studio XE7, RAD Studio XE8, Third Party Components, TMS Software, Uncategorized | Comments Off on TMS Day Meerbusch Nov 23, 2017

TMS Passkit at German Code Rage 2017

This year I will hold a presentation at the German Code Rage 2017. You can join it on Thursday, 22th at 1 pm.

I will talk about the new TMS PassKit component. With TMS PassKit, wallet PassKit files can be generated for use with the iOS / iPhone wallet of all types. Wallet is an application on Apple iOS that manages tickets, vouchers, boarding passes, store cards or other virtual objects. It is a part of the Apple Pay system which supports payment by NFC or Apple Wallet.

TMS Software, established in 1995, is a software development company specialized in:

  • VCL, FMX, LCL, FNC, ASP.NET, .NET, IntraWeb component development
  • Windows, Web, Android, iOS, macOS, Linux, Node.js development projects
  • Training, consulting & custom project development

TMS software has a team of experienced developers with main office in Europe, Belgium as well as offices in Uruguay and Brazil.

Posted in C++-Builder, Delphi, RAD Studio 10 Seattle, RAD Studio 10.1 Berlin, RAD Studio 10.2 Tokyo, RAD Studio XE8, Third Party Components, Uncategorized | Comments Off on TMS Passkit at German Code Rage 2017

Converted dfm to Text Format

Today Stefan Glienke mentioned at Google+ that there are some libraries which still use the binary format for dfm files. This is an issue since it is nearly impossible to recognize the changes in your vcs.

I do remember old Delphi version which only supported the binary format. In the Delphi bin folder you can find the convert.exe tool that converts a dfm file to the text format and vice versa. You can simply drop a dfm file on it.

Stefan mentioned that one if the libs with binaries is Abbrevia so that I converted them to the text format.

Posted in C++-Builder, Delphi, RAD Studio 10.2 Tokyo, Third Party Components, Tips and Tricks, TurboPack, Uncategorized | Comments Off on Converted dfm to Text Format

Free Capacities

Hi all,

I currently have free capacities. I’m looking for remote contract work. I’m a specialist in all Delphi versions, particularly components, SQL databases, ORM and multi-threading.


Thanks,

Roman

Posted in C++-Builder, Delphi, FireMonkey, RAD Studio 10 Seattle, RAD Studio 10.1 Berlin, RAD Studio 10.2 Tokyo, RAD Studio XE5, RAD Studio XE6, RAD Studio XE7, RAD Studio XE8, Third Party Components, Tips and Tricks, Uncategorized | Comments Off on Free Capacities

Supports

This week I had to maintain some legacy code that uses many interfaces and supports in order to find out if a specific interface is supported:

type
  IMyInterface = interface(IInterface)
    ['{F500EEDD-032E-4D15-A8C0-EFF673C2AF01}']
    procedure DoSomething;
  end;

procedure MyProcedure(const AIntf: IInterface);

implementation

uses
  System.SysUtils;

procedure MyProcedure(const AIntf: IInterface);
var
  lMyIntf: IMyInterface;
begin
  if Supports(AIntf, IInterface, lMyIntf) then
    lMyIntf.DoSomething;
end;

One of the tasks I had to do is to replace the interfaces with pure Delphi objects. That’s why I wondered if there is a chance to write something similar for objects.

I played a bit and found the following:

type
  TObjectHelper = class helper for TObject
  public
    function Supports<T: class>(out ADest: T): Boolean;
  end;

...

{ TObjectHelper }

function TObjectHelper.Supports<T>(out ADest: T): Boolean;
begin
  if Self.InheritsFrom(T) then
  begin
    ADest := T(Self);
    Result := True;
  end
  else
  begin
    ADest := nil;
    Result := False;
  end;
end;

...

var
  lObject: TObject;
  lMyObject: TMyObject;
begin
  ...
  if lObject.Supports<TMyObject>(lMyObject) then
    lMyObject.DoSomething;
Posted in Delphi, RAD Studio 10.2 Tokyo, Tips and Tricks, Uncategorized | Comments Off on Supports

FreeAndNil

There are a lot of articles about the use and abuse of FreeAndNil but there is one point I really don’t like about FreeAndNil: It is not type-safe. Let’s have a look at the implementation:

{ FreeAndNil frees the given TObject instance and sets the variable reference
  to nil.  Be careful to only pass TObjects to this routine. }

procedure FreeAndNil(var Obj); inline;
...

procedure FreeAndNil(var Obj);
{$IF not Defined(AUTOREFCOUNT)}
var
  Temp: TObject;
begin
  Temp := TObject(Obj);
  Pointer(Obj) := nil;
  Temp.Free;
end;
{$ELSE}
begin
  TObject(Obj) := nil;
end;
{$ENDIF}



The comment describes the issue: “Be careful to only pass TObjects to this routine.” That’s why I would implement it in a different way:

type
  TObjectHelper = class helper for TObject
  public
    class procedure FreeAndNil<T: class>(var AValue: T); inline; static;
  end;

{ TObjectHelper }

class procedure TObjectHelper.FreeAndNil<T>(var AValue: T);
{$IF not Defined(AUTOREFCOUNT)}
var
  lTemp: TObject;
begin
  lTemp := AValue;
  AValue := nil;
  lTemp.Free;
end;
{$ELSE}
begin
  AValue := nil;
end;
{$ENDIF}

This code is type-safe and don’t use pointer arithmetic. Maybe I will ask Marco if there is a chance to add the generic FreeAndNil method directly to TObject.

Posted in Delphi, RAD Studio 10.2 Tokyo, Tips and Tricks, Uncategorized | Comments Off on FreeAndNil

VirtualTreeView Version 6.6.0

I just updated the TurboPack version of the VirtualTreeView to the version 6.6.0 and asked Embarcadero to update GetIt.

Posted in Delphi, RAD Studio 10.2 Tokyo, SourceForge, Third Party Components, TurboPack, Uncategorized | Comments Off on VirtualTreeView Version 6.6.0

Nice Approach For Exception Safe Code

Maybe everyone knows the issue with code that is not exception safe. Let’s see an example:

function MyFunction: TMyObject;
begin
  Result := TMyObject,Create;
  Result.DoSomething;
end;

The function MyFunction returns an instance of an object which is normally no problem. But MyFunction creates the instance and then runs further code. And in case of an exception no one “cares” about the instance and you will simply get a memory leak.

That’s why people normally avoid functions that return instances or write the code in an exception safe way:

function MyFunction: TMyObject;
begin
  Result := TMyObject,Create;
  try
    Result.DoSomething;
  except
    on E: Exception do
    begin
      Result.Free;
      raise;
    end;
  end;
end;

At this point some purists would say that the Result should also be assigned to nil after it had been destroyed.

function MyFunction: TMyObject;
begin
  Result := TMyObject,Create;
  try
    Result.DoSomething;
  except
    on E: Exception do
    begin
      FreeAndNil(Result);
      raise;
    end;
  end;
end;

I don’t want to start a long discussion about FreeAndNil but what people, including myself, don’t like is to catch an exception in order to raise it again a moment later.

Instead the code could be written with a try-finally-block:

function MyFunction: TMyObject;
var
  lMyObject: TMyObject;
begin
  lMyObject := TMyObject,Create;
  try
    lMyObject.DoSomething;
    Result := lMyObject;
    lMyObject := nil;
  finally
    lMyObject.Free;
  end;
end;

The tricks are:

  1. Free can be called if an instance is nil.
  2. Finally is always called.
  3. After assigning the Result no further code that could cause an exception is called.
Posted in Delphi, FireMonkey, RAD Studio 10 Seattle, RAD Studio 10.1 Berlin, RAD Studio 10.2 Tokyo, RAD Studio XE5, RAD Studio XE6, RAD Studio XE7, RAD Studio XE8, Tips and Tricks | Comments Off on Nice Approach For Exception Safe Code

PNG Components and Tokyo

This week I received an email from Uwe Raabe that he has updated his png components under bitbucket.

That’s why I just updated the TurboPack version under GitHub.

As I mentioned in a previous post the RAD Studio 10.2 Tokyo version of TurboPack of is now located at a different place.

I will also ask Marco to update GetIt.

Posted in C++-Builder, Delphi, RAD Studio 10.2 Tokyo, Third Party Components, TurboPack, TurboPower | Comments Off on PNG Components and Tokyo

TFile.Size 2.0

Yesterday I got a suggestion for a better implementation for TFile.Size from Stefan Glienke. Many thanks for it, Stefan.

In order to make the code compatible to other functions in System.IOUtils, I modified it in the way that I’m raising an EInOutError if there is a problem.

I could compile the code for all platforms Win32, Win64, MacOS32, iOS32, iOS64, Android32 and Linux64.

unit System.IOUtils.Helper;

interface

uses
  System.IOUtils;

type
  TFileHelper = record Helper for TFile
  public
    class function Size(const APath: string): Int64; static;
  end;

implementation

{$IFDEF MSWINDOWS}
uses
  System.SysUtils, Winapi.Windows;
{$ENDIF}
{$IFDEF POSIX}
uses
  System.SysUtils, Posix.SysStat;
{$ENDIF}

{ TFileHelper }

class function TFileHelper.Size(const APath: string): Int64;
{$IFDEF MSWINDOWS}
var
  lAttributes: TWin32FileAttributeData;
begin
  if GetFileAttributesEx(PChar(APath), GetFileExInfoStandard, @lAttributes) then
  begin
    Int64Rec(Result).Lo := lAttributes.nFileSizeLow;
    Int64Rec(Result).Hi := lAttributes.nFileSizeHigh;
  end
  else
    raise EInOutError.Create(SysErrorMessage(GetLastError));
end;
{$ENDIF}
{$IFDEF POSIX}
var
  lStat: _stat;
  lFileName: Pointer;
  lMarshaller: TMarshaller;
  lError: Integer;
begin
  lFileName := lMarshaller.AsAnsi(APath, CP_UTF8).ToPointer;
  lError := stat(lFileName, lStat);
  if lError = 0 then
    Result := lStat.st_size
  else
    raise EInOutError.Create(SysErrorMessage(lError));
end;
{$ENDIF}

end.
Posted in C++-Builder, Delphi, RAD Studio 10.1 Berlin, RAD Studio 10.2 Tokyo, Uncategorized | Comments Off on TFile.Size 2.0