Software Developer, Technology Enthusiast, Retro and Husband and Dad based in Melbourne.

Delphi

NovuscodeLibrary update for Delphi 10.4

An update to the NovuscodeLibrary – a Delphi library of utility functions and non-visual classes for Delphi 10.4 is now ready.

https://github.com/novuslogic/NovuscodeLibrary

The next big goal will be a Documentation Wiki using CodeImatic.codegen – CodeDoc plugin. Still a work in progress.

https://github.com/novuslogic/NovuscodeLibrary/issues/11

Also an upgrade and new samples.

https://github.com/novuslogic/NovuscodeLibrary/issues/12

Changelog

ToDo

and that was 2019 in Review.

This blog has been very quiet this year, lots of reasons, mostly work-related has kept me away.

Some milestones were achieved this year:

NovuscodeLibrary

NovuscodeLibrary is a Delphi library of utility functions and non-visual classes.

  • New package NovusCodeLibrary_cURL.dpk – cURL function library
  • New package NovusCodeLibrary_WebUtils.dpk – Web functions library
  • Now support Delphi 10.3 and packages

https://github.com/novuslogic/NovuscodeLibrary

Changelog

ToDo

Adding features or fixing bugs to Novuscodelibrary, it’s general done organically. The next feature supported:

CodeImatic

CodeImatic is a PascalScript based toolchain for building and deployment.

CodeImatc.build

CodeImatic.build is a PascalScript based build and deployment engine.

https://github.com/novuslogic/CodeImatic.build

CodeImatc.codegen

CodeImatic.codegen is a PascalScript template driven source code and static website generator.

https://github.com/novuslogic/CodeImatic.codegen

CodeImatic – Multiple features have been added and moving towards  an early beta release next year.

DelphiAWSSDK

The Delphi AWS SDK enables Delphi/Pascal developers to easily work with Amazon Web Services.

DelphiAWSSDK

Changelog

The next version of DelphiAWSDK v.04 will have a full translation of Amazon DynamoDB https://aws.amazon.com/dynamodb/ using the new experimental Code-Generation based on CodeImatic.codegen https://github.com/novuslogic/CodeImatic.codegen

Using WordPress on Amazon Lightsail

https://leanpub.com/wordpressawslightsail/

I’m develpoing  a new book called “Using WordPress on Amazon Lightsail” which will be pushlished early next year, so sign up with the “Notify Me When This Is Published” button.

Happy New Year.

DelphiAWSSDK v0.2.0

The Delphi AWS SDK enables Delphi/Pascal developers to easily work with Amazon Web Services.

https://github.com/novuslogic/DelphiAWSSDK/releases/tag/v0.2.0

Summary of updates

  • Updated support Delphi XE to Delphi X10.2
  • Tested support for Windows 32/64Bit, MacOSX 32Bit
  • New TAmazonIndyRESTClient and TAmazonDelphiRESTClient classes
  • Updated TAmazonSignatureV4 class to be less reliant on Indy,  allowing for cross-platform development.
  • THashSHA2 supported in unit Amazon.Utils for Delphi XE8 and up.

 

DelphiLibSass – A Delphi wrapper for LibSass

DelphiLibSass is Delphi wrapper around libsass a C/C++ implementation of a Sass compiler.

Based on the version of libsass 3.4 http://libsass.org

DelphiLibSass API is simply composed of a main TDelphiLibSass class:

TDelphiLibSass.ConvertToCss converts a SCSS string to a CSS

Try
  FDelphiLibSass := TDelphiLibSass.Create('libsass.dll');
  FDelphiLibSass.LoadDll;

  FScssResult := FDelphiLibSass.
      ConvertToCss('$font-stack: Helvetica, sans-serif; body { font: 100% $font-stack; }');

  writeln(FScssResult.CSS);
Finally
  FScssResult.Free;
  FDelphiLibSass.Free; 
end;

TDelphiLibSass.ConvertFileToCss converts a SCSS file to a CSS

Try
  FDelphiLibSass := TDelphiLibSass.Create('libsass.dll');
  FDelphiLibSass.LoadDll;

  FScssResult := FDelphiLibSass.ConvertFileToCss('test.scss');

  writeln(FScssResult.CSS);
Finally
  FScssResult.Free;
  FDelphiLibSass.Free; 
end;

Basic example on how to use the Delphi wrapper

https://github.com/novuslogic/DelphiLibSass/tree/master/Sample

References

DelphiLibSass
https://github.com/novuslogic/DelphiLibSass/

Delphi and .NET Interop with JVCL

There are different methods for Delphi to communicate with the .NET Framework:

  • Commercial projects e.g. Remobjects Hydra, Atozed CrossTalk and Managed VCL etc.
  • Importing .NET Assembly using the Import Component Wizard.
  • Or Open Source method using JVCL.

Why choose JVCL over the commercial projects and the Import Component Wizard which is part of Delphi?

  • Open Source e.g. free as in beer.
  • Independent of regasm.exe which registers Class Libraries into the Global Assemble Cache (GAC)

How does JclDotNet work?

JVCL provides communication to the .NET Framework using the JclDotNet unit, by providing variant based
late bound automation to the .NET class library.

This post will provide two examples by stepping through each part, which should provide a basic grounding on how the 
JVCL JclDotNet unit communicates with .NET Framework.

For these examples your Delphi must have JVCL 3.45 or higher installed and for  the C# Class Library .NET 4.5 Framework
 (Visual Studio 2012).

Example 1

This example demonstrates a basic adding of two numbers together, by calling the C# class library Example1ClassLibrary.DLL

Delphi Example
  • To start the TJclClrHost class must initialize a .NET Framework – Common Language Runtime (CLR) and start the host:
Host := TJclClrHost.Create('v4.0.30319');
Host.Start();
  • NOTE: By default if you leave the ClrVer variable blank, it defaults to v2.0.50727.
Host := TJclClrHost.Create;
  • For this example we will be using CLR v4.0.30319 which supports either .NET 4.5 or .NET 4 Framework.
  • C# Class Library must now be initialize and Obj: OleVariant for the access to method:
Obj := Host.DefaultAppDomain
.CreateInstance('Example1ClassLibrary' {.NET Assemble Name},

'Example1ClassLibrary.Example1' {Namespace.Classname})

.UnWrap();
  • First part is the name of .NET Assemble File ‘Example1ClassLibrary.dll’.
  • ‘Example1ClassLibrary.Example1‘ next part is the namespace and the classname
  • Accessing this method from the C# Class Library as simple has keeping the name and the parameters the same as the class library:
Result := Obj.AddFunction(aXValue, aYValue);
  • Release the CLR host just stop and free the TJclClrHost class:
Host.Stop();
Host.Free;
Full Function
function TfrmMain.AddFunction(aXValue: Integer; aYValue:Integer): Integer;
var
  Host: TJclClrHost;
  Obj: OleVariant;
begin
  try
    Host := TJclClrHost.Create('v4.0.30319');
    Host.Start();

    Obj := Host.DefaultAppDomain
        .CreateInstance('Example1ClassLibrary',
        'Example1ClassLibrary.Example1')
        .UnWrap();

     Result := Obj.AddFunction(aXValue, aYValue);

    Host.Stop();
    Host.Free;
  Except
     on E : Exception do
     begin
       ShowMessage('Exception class name = '+E.ClassName + ' ' + 'Exception message = '+E.Message);
     end;
  end;
end;

C# Class Library

Some basic setting up of example 1 Class Library allowing Delphi work with Interop Services:

  • Include in your namespace for the Interop Services
using System.Runtime.InteropServices;
  • To expose the class to COM access to Delphi
[ComVisible(true)]
public class Example1
  • All functions must be public
public int AddFunction(int aXValue, int aYValue)
{
return aXValue + aYValue;
}
Class Library
namespace Example1ClassLibrary
{
    [ComVisible(true)]
    public class Example1
    {
        public int AddFunction(int aXValue, int aYValue)
        {
            return aXValue + aYValue;
        }
    }
}

Example 2

In this example we take the basic adding of two numbers together and expand out how Delphi can access the Example2ClassLibrary.DLL using the mscorlib_TLB import library:

Delphi Example
uses
mscorlib_TLB, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,? StdCtrls, JclDotNet;
  • NOTE: mscorlib_TLB should be the first unit.
  • Initializing the host to .NET Framework in the formcreate event:
procedure TfrmMain.FormCreate(Sender: TObject);
begin
   FClrHost := TJclClrHost.Create('v4.0.30319');

   FClrHost.Start;
end;
  • Setup the access to the Class Library path and application:
Fads.ApplicationBase := '..\Example2\Debug\Win32\';
Fad := FClrHost.CreateAppDomain('myNET', Fads);
  • NOTE: CreateAppDomain(‘myNET’ should be a different name if two or more a being called.
  • The C# Class Library must now be initialize and Obj: OleVariant for the access to the method:
obj := (Fad as _AppDomain).CreateInstanceFrom('Example2ClassLibrary.dll',
     'Example2ClassLibrary.Example2');
ov := obj.Unwrap;result := ov.AddFunction(aXValue, aYValue);
  • To release the CLR host just stop and free has been setup on the FormDestory event:
procedure TfrmMain.FormDestroy(Sender: TObject);
begin
  FClrHost.Stop();
  FClrHost.Free;
end;
Full Function
function TfrmMain.AddFunction(aXValue: Integer; aYValue:Integer): Integer;
var
  Fads: TJclClrAppDomainSetup;
  Fad: TJclClrAppDomain;
  Ov: OleVariant;
  obj: _ObjectHandle;
begin
  try
    Fads := FClrhost.CreateDomainSetup;

    Fads.ApplicationBase := '..\Example2\Debug\Win32\';
    Fad := FClrHost.CreateAppDomain('myNET', Fads);
    obj := (Fad as _AppDomain).CreateInstanceFrom('Example2ClassLibrary.dll',
         'Example2ClassLibrary.Example2');
    ov := obj.Unwrap;
    result := ov.AddFunction(aXValue, aYValue);
  except
    on E : Exception do
     begin
       ShowMessage('Exception class name = '+E.ClassName +
          ' ' + 'Exception message = '+E.Message);     end;
  end;
end;

Download Examples

https://github.com/acj1971/DelphiDotNETInteropJVCLExamples

Links

JVCL
http://jvcl.delphi-jedi.org/

.NET 4.5 Framework
http://www.microsoft.com/en-au/download/details.aspx?id=30653

Common Language Runtime (CLR)
http://msdn.microsoft.com/en-us/library/8bs2ecf4.aspx

Remobjects Hydra
http://www.remobjects.com/hydra/

Atozed CrossTalk
http://www.atozed.com/CrossTalk/index.en.aspx

Managed VCL
http://www.managed-vcl.com/

Import Component Wizard
http://docwiki.embarcadero.com/RADStudio/XE3/en/Import_Component_Wizard