The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,426 other followers

Archive for the ‘Delphi’ Category

database connection – Looking for a generic way to pool TCusomConnection in Delphi – Stack Overflow

Posted by jpluimers on 2018/10/11

What is the proper way for pooling of TCustomConnection instances in Delphi, that allows to distinguish between instances that have effectively equal connection properties and the ones that are effectively unequal?

I’ve tried searching the RTL and VCL sources and didn’t find a generic way.

I could copy either of the specific ones I found (see list below) and adapt them to a more generic solution or adapt one of the answers in #16404051 to be for TCustomConnection, but I wonder if there is an existing solution for TCustomConnection in the first place.

Specific ones I found in Delphi XE8:

  • DBX: unit Data.DBXPool
  • FireDAC: unit FireDAC.Stan.Pool
  • IBX: unit IBX.IBConnectionBroker

Source [WayBackdatabase connection – Looking for a generic way to pool TCusomConnection in Delphi – Stack Overflow

Hopefully by now I’ve some implementation for this that works nicely.

If not, these might get me started too:

In the .NET world, I take these things for granted, and it looks like ADO already does it out of the box as well:

–jeroen

via: [WayBack] Is there a Delphi library that allows for pooling of TCustomConnection… – Jeroen Wiert Pluimers – Google+

Posted in Delphi, Delphi XE8, Development, Software Development | 2 Comments »

TObjectHelper for easier debugging a cast mismatch and a typed FreeAndNil

Posted by jpluimers on 2018/10/10

The below came in really useful in an old project I took over that was full of bugs having to do with improper casts and FreeAndNil usage.

EDIT 20181010: WordPress.com keeps mangling angle-brackets in pre and code sections, so I added the code to a gist; see link below.

First the examples.

procedure TMyServer.UnbindFromIdTcpServerStatusContext(const aContext: TIdContext);
var
  lClientSession: TClientSession;
begin
  lClientSession := TObjectHelper.Cast<TClientSession>(aContext.Data);
...
end;

type
  TBaseDataInterface = class(TObject)
  strict private
    FDatabase:      TIBDatabase;
    FTransaction:   TIBTransaction;
...
  end;


destructor TBaseDataInterface.Destroy();
begin
  TObjectHelper.FreeAndNil(FDatabase);
  TObjectHelper.FreeAndNil(FTransaction);
...
  inherited Destroy();
end;

And the implementation.

unit ObjectHelperUnit;

interface

type
  TObjectHelper = record
    class function Cast<T: class>(const aValue: TObject): T; static;
    class procedure FreeAndNil<T: class>(var Value: T); static;
  end;

implementation

uses
  System.SysConst,
  System.SysUtils;

class function TObjectHelper.Cast<T>(const aValue: TObject): T;
var
  lException: Exception;
begin
  if Assigned(aValue) then
  begin
    if aValue is T then
      Result := T(aValue)
    else
    begin
      lException := EInvalidCast.CreateFmt('%s; actual type %s but expected %s.',
        [SInvalidCast, aValue.QualifiedClassName, T.QualifiedClassName]);
      raise lException;
    end;
  end
  else
    Result := nil;
end;

class procedure TObjectHelper.FreeAndNil<T>(var Value: T);
begin
  System.SysUtils.FreeAndNil(Value);
end;

end.

–jeroen

Gist:

Posted in Delphi, Development, Software Development | 16 Comments »

A Key’s Odyssey – the path of a keystroke message through the VCL

Posted by jpluimers on 2018/10/09

Blast from the past, but still relevant, this article by Peter Below:

This article follows the path of a keystroke message through the VCL. You will learn how the key processing is implemented, how the OnKey events work and what intervention points for the programmer can be found in the whole process. In addition, things like message processing are explained, and you will learn how to trace messages in the debugger from the message loop to their eventual destination.

Source: [WayBackA Key’s Odyssey

Via: [WayBack] Vcl.Controls.pasprocedure TWinControl.CNKeyDown(var Message: TWMKeyDown);..if IsMenuKey(Message) then Exit; … – Attila Kovacs – Google+

-jeroen

Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »

What’s the point of having abstract classes in Delphi? 

Posted by jpluimers on 2018/10/04

There was an interesting thread a while ago: [WayBack] What’s the point of having abstract classes in Delphi? – Agustin Ortu – Google+

The answer is none (the documentation warns you against it – see Constructing instance of abstract class –  the compiler doesn’t), so Stefan Glienke submitted this bug: RSP-10235: No warning for .Create on class declared as TClass = class abstract

This post is a reminder to myself to see if any progress has been made by the compiler engineers.

–jeroen

Posted in Delphi, Development, Software Development | 9 Comments »

On my list to try (about half a year since it appeared): A new mutlti-threading library for Delphi. (darkThreading) – Chapman World

Posted by jpluimers on 2018/10/03

With fresh libraries – like new Delphi and Windows versions – I usually take a pause to see if any major updates have been published to stabalise things.

So about half a year after the release of A new mutlti-threading library for Delphi. (darkThreading) – Chapman World [WayBack], this is a reminder for me to try it.

With the Task Parallel Library still not being up to par, I wonder how DarkThreading compares to the very stable [WayBack] GitHub – gabr42/OmniThreadLibrary: A simple and powerful multithreading library for Delphi.

The source is at [WayBack] GitHub – chapmanworld/darkThreading: Platform agnostic light-locking threading library for Delphi (part of the DarkGlass project).

Note that by now it has moved to [WayBack] DarkGlass/darkLibs/darkThreading at master · chapmanworld/DarkGlass · GitHub (thanks Stefan Glienke for figuring that out)

One comment already: the [WayBack] darkThreading/Building.md at master · chapmanworld/darkThreading · GitHub describes dependencies on the below libraries, but does not use git modules (see [WayBack] Git – git-submodule Documentation) to reference to known stable commits of them:

In the man time, Edwin Yip has reviewed it: [WayBack] Simple Comparison of OmniThreadLibrary and darkThreading (http://chapmanworld.com/2018/05/24/a-new-mutlti-threading-library-for-delphi-darkthreading/) … – Edwin Yip – Google+ after in may he indicated he would look into it at a later stage [WayBack] http://chapmanworld.com/2018/05/24/a-new-mutlti-threading-library-for-delphi-…

–jeroen

Via [WayBackCraig Chapman on Twitter: “My threading library for Delphi (darkThreading) https://t.co/Jo7nVGzsNY”

 

Posted in Delphi, Development, Software Development | 2 Comments »

 
%d bloggers like this: