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,854 other subscribers

Archive for the ‘Delphi’ Category

Convert an object instance into a JSON string and making use of custom attributes – Flix Engineering

Posted by jpluimers on 2019/09/24

For my link archive, [WayBack] Convert an object instance into a JSON string and making use of custom attributes – Flix Engineering:

JSON, JSONMarshalled, JSONName Delphi Convert an object instance into a JSON string and making use of custom attributes

This is a welcome explanation as in [WayBack] REST.Json.Types – RAD Studio API Documentation, these attributes have very shallow documentation:

Via: [WayBack] Is there any documentation for attribute and Json? uses Rest.Json, Rest.Json.Types; [JSONName(‘TokenName’)] – Thomas Bornhaupt – Google+

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »

Dave’s Development Blog – Using CodeSite on interfaced objects

Posted by jpluimers on 2019/09/20

Reminder to self: [WayBackDave’s Development Blog – Using CodeSite on interfaced objects:

Note to self…

If using CodeSite to log Constructor and Destructor behaviour on interfaced objects, make sure its the first unit in the project so that it is the first unit initialised AND THE LAST unit finalised!

This will save you hours and hours hunting down shutdown AVs 🙁

Or in my projects, the uses list in the Delphi project should be this order:

  1. FastMM4Bootstrap
  2. CodeSite

Via: [WayBackUsing CodeSite on interfaced objects  – David Hoyle – Google+

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »

Hi, We need to implement a functionality in our VCL application where the user…

Posted by jpluimers on 2019/09/19

In recent Delphi versions one is encouraged to use the routines from System.NetEncoding. Also Soap.EncdDecd is only a wrapper to them. Even if you use the stream based implementations the whole stream is read into a TBytes. So no real gain there any more.

Source: [WayBackHi, We need to implement a functionality in our VCL application where the user…

Related:

–jeroen

Posted in Delphi, Development, SOAP/WebServices, Software Development | Leave a Comment »

GitHub – ultraware/DelphiGrpc: DelphiGrpc is a Delphi implementation of the realtime and streaming gRPC protocol (http://grpc.io).

Posted by jpluimers on 2019/09/18

For my link list: [WayBack] GitHub – ultraware/DelphiGrpc: DelphiGrpc is a Delphi implementation of the realtime and streaming gRPC protocol (http://grpc.io).

The following libraries are used:

Via [WayBack] Interesting finding today – DelphiGrpc – a grpc.io implementation in Delphi – Edwin Yip – Google+

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »

GExperts: Copy Component Names

Posted by jpluimers on 2019/09/17

Sometimes your toolbox can already things you forgot it could: [Archive.is] GExperts Help.

Via:

–jeroen

Posted in Delphi, Development, GExperts, Software Development | Leave a Comment »

Delphi: when calling TThread.Synchronize, ensure the synchronised method handles exceptions

Posted by jpluimers on 2019/09/17

Since about a decade, TThread has a few overloaded [WayBack] Synchronize methods which all allow some specified synchronised method to run in the context of the main thread:

Any exceptions raised in that methods are caught using [WayBackSystem.AcquireExceptionObject and re-raised in the calling thread.

If that happens, you loose a piece of the stack information. I knew that, but found out the hard way that it does because I had to hunt for bugs through inherited code written by people that did not know.

This was part of the stack trace that code would show during an exception:

Exception EAccessViolation at $004D732F: Access violation at address $00409174 in module ''.....exe''.
Read of address 80808080
StackTrace:
(000D632F){.....exe} [004D732F] System.Classes.TThread.Synchronize$qqrp41System.Classes.TThread.TSynchronizeRecordo (Line 14975, "System.Classes.pas" + 40) + $0
(000D6430){.....exe} [004D7430] System.Classes.TThread.Synchronize$qqrxp22System.Classes.TThreadynpqqrv$v (Line 15007, "System.Classes.pas" + 9) + $A
(005D6E61){.....exe} [009D7E61] IdSync.DoThreadSync$qqrp18Idthread.TIdThreadynpqqrv$v (Line 281, "IdSync.pas" + 21) + $6
(005D6E87){.....exe} [009D7E87] IdSync.TIdSync.SynchronizeMethod$qqrynpqqrv$v (Line 326, "IdSync.pas" + 2) + $8

Exception EAccessViolation at $00409174: Access violation at address $00409174 in module ''.....exe''. Read of address $80808080 with StackTrace
(00008174){.....exe} [00409174] System.@IsClass$qqrxp14System.TObjectp17System.TMetaClass + $C

The first exception has a different address than the one in the exception message.

Which means that you miss the whole stack path to the _IsClass call (the underlying method implementing the as keyword) that the actual exception was initiated at.

And yes: the $80808080 is the FastMM4 marker for freed memory, so this was a use-after-free scenario.

A simple wrapper like this using a central logging facility gave much more insight in the actual cause:

procedure RunLoggedMethod(AMethod: TMethod);
begin
  try
    AMethod();
  except
    on E: Exception do
    begin
      Logger.LogExceptionDuringMethod(E, AMethod);
      raise; // mandatory to stay compatible with the old un-logged code
    end;
  end;
end;

Then call it like this inside a thread descendant:

Synchronize(RunLoggedMethod(MethodToRunInMainThread));

The old code was like this:

Synchronize(MethodToRunInMainThread);

This was quite easy to change, as I already had boiler code around exported DLL functions that had a similar construct (without the raise; as exceptions cannot pass DLL boundaries unless very specific circumstances hold).

Similar methods are needed to encapsulate procedure TIdSync.Synchronize(), procedure TIdSync.SynchronizeMethodprocedure TIdThread.Synchronize(Method: TThreadMethod) and [WayBack] Queue overloads:

–jeroen

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

Delphi / Stefan Glienke: I looked into IntroSort … and the Microsoft implementation … Here is my current implementation

Posted by jpluimers on 2019/09/12

For my link archive: [WayBack] Delphi / Stefan Glienke: I looked into IntroSort … and the Microsoft implementation … Here is my current implementation

[WayBackDelphi IntroSort by Stefan Glienke

–jeroen

https://bitbucket.org/snippets/sglienke/64LG6b/introsort

 

Posted in Delphi, Development, Software Development | Leave a Comment »

C# (and presumably Delphi): why parameterless record constructors are absent

Posted by jpluimers on 2019/09/12

For my link archive.

Full text at: [WayBack] … why the Delphi language does not allow parameterless constructors… – David Heffernan – Google+

Abstract:

+Stefan Glienke deleted his post about parameterless record constructors, presumably due to all the off topic comments.

.net at CLR level does allow parameterless constructors on structs. But the C# language bans them: https://msdn.microsoft.com/en-us/library/saxz13w4.aspx

Jon Skeet posted an answer on SO way back in 2008 on this topic: http://stackoverflow.com/a/333840/ From that answer:

—-
The CLR allows value types to have parameterless constructors, but C# doesn’t. I believe this is because it would introduce an expectation that the constructor would be called when it wouldn’t. For instance, consider this:

MyStruct[] foo = new MyStruct[1000];


—-

My guess is that Embarcadero decided to ban parameterless constructors on Delphi records for the same reason. Or perhaps they just copied the rules from C# without realising that the CLR supported parameterless struct constructors.

References:

--jeroen

Posted in .NET, C#, Delphi, Development, Jon Skeet, Software Development | Tagged: | Leave a Comment »

delphi: you can only access protected identifiers from parent classes in your own “Self” scope, or when you are “friends” with your parent (so you are in the same unit)

Posted by jpluimers on 2019/09/11

An interesting question from a while back: [WayBack] delphi – Should a descendant class’ method’s variable that is identical to Self, have access to its ancestor’s protected methods? – Stack Overflow

In unit A:

TParent = class
protected
  function DoSomething: TParent;
end;

In unit B:

TChild = class(TParent)
public
  procedure DoAnotherThing;
end;

implementation

procedure TChild.DoAnotherThing;
begin
  DoSomething.DoSomething
end;

This won’t compile, throwing a

cannot access protected symbol TParent.DoSomething

The kicker here is that the error message makes you think you are operating in Self context, but you are not as you are calling DoSomething.DoSomething where only the first DoSomething is in your Self context, but the second .DoSomethingis in the context of any TParent instance trying to access a public identifier.

Stefan Glienke posted [WayBack] a more elaborate answer explaining some workarounds.

–jeroen

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

Is there a way to use the JVCL’s TJvXxxAppStorage to store float values as s…

Posted by jpluimers on 2019/09/10

For my link archive: [WayBack] Is there a way to use the JVCL’s TJvXxxAppStorage to store float values as strings (e.g. “10.152”) rather than hex dumps and also control the decimal s… – Thomas Mueller (dummzeuch) – Google+

Relevant sources:

–jeroen

 

Posted in Delphi, Development, Software Development | Leave a Comment »