Spring4D hidden gems

I absolutely love the Spring4D libraries and have used them for years. But I am realising I have only scratched the surface. So I thought I would post some of my favourite but less well known features.

I was today years old when I discovered the TBuffer type - it’s part of the cryptography code - but it’s immensely useful

  • Assignable to/from TBytes
  • ToHexSting method
  • Load from/save to TStream
  • ToString method
  • Access to the underlying memory via Memory property (pointer).
  • Size property
  • Bitwise And/Or/Xor operations.

It’s just an incredibly well thought out type. It’s basically what TBytes should have been!

I only discovered it today when I needed to do some hashing - the spring4d crpytography code is pretty neat too, with support for MD5, SHA1,SHA256, SHA384 and SHA512.

Kudos to @sglienke

https://bitbucket.org/sglienke/spring4d/src/develop/

BTW, Use the develop branch (which is 2.0rc5) - it’s very stable.

Feel free to chime in with any others you have discovered.

5 Likes

The whole of Spring4D is a gem. I too have only scratched the surface (we primarily use the core features in Collections, Services, Container). I haven’t looked at new features or changes for the last couple of years (note to self - to review).

One hidden gem that we use is Spring.SystemUtils.TEnum that provides convenient ways to convert between enums and strings and integers (e.g. persistence).

Thanks for the tip on 2.0rc5.

2 Likes

FWIW Kudos for TBuffer and most things in Spring.Crypto goes to Baoquan Zuo (aka Paul) the author of Spring4D. :sunglasses:

4 Likes

I didn’t know about the Google Group : https://groups.google.com/g/spring4d

And I expect en.Delphi-Praxis.net is a good source for queries also : Forum for Spring4D - Delphi Third-Party - Delphi-PRAXiS [en]

I love DelphiPraxis but it sucks for notifications - any post into the Google group directly goes to my emails (well when Google does not mess it up and leaves it closed for ages due to a false positive on some malicious content filter)
The same is the case for StackOverflow - once a week or so I check the spring4d tag.

1 Like

I use RSS - I have a “bot” (at the moment, a service on a Windows machine) that checks feeds, and posts new entries to related channels in my Slack workspace, e.g. #forum-posts for DP and SO, and #qp for Quality Portal :slight_smile:

Unique count in Spring4D - 4 ways + 1 other

unit U_unique_count;

interface

  procedure unique_count_main;


implementation
uses
  System.SysUtils, Spring, Spring.Collections, U_Gen_Data;

const
  N    = 20000;
  crlf = #13#10;


  function uniq_spring_set : string;
  begin
  var s := TCollections.CreateSet(data);
      exit('Spring Set : ' + s.Count.ToString + crlf);
  end;


  function uniq_spring_list : string;
  begin
  var l := TCollections.CreateList(data);
      exit('Spring List : ' + l.Distinct.Count.ToString + crlf);
  end;


  function uniq_spring_sortedlist : string;
  begin
  var l := TCollections.CreateSortedList(data);
      exit('Spring SortedList : ' + l.Distinct.Count.ToString + crlf);
  end;


  function uniq_spring_enum : string;
  begin
      exit('Spring Enumerable : ' + TEnumerable.From(data)
                                               .Distinct
                                               .Count
                                               .ToString  + crlf);
  end;


  function uniq_array_int : string;
  begin
  var last:= -1;
  var cnt :=  0;
      TArray.Sort<integer>(data);
      for var i in data do
          if i<>last then begin
                            inc(cnt); last := i;
                          end;
      exit('TArray : ' + cnt.ToString + crlf);
  end;



  procedure unique_count_main;
  begin
     generate_uniq_data(N);

     writeln(uniq_spring_set);
     writeln(uniq_spring_list);
     writeln(uniq_spring_sortedlist);
     writeln(uniq_spring_enum);
     writeln(uniq_array_int);
  end;

end.

Spring4D (and lambda) codegen vs a traditional raw loop.

1 Like

Errrnnntttttt.

Abort. Abort. :sweat_smile:

It was early in the morning, ok?

I missed that there was a call away outside this section (of course there is).
Quite a bit goes on there, there is an interface behind the scenes … so forget my claim here. :expressionless::skull:

[ BUT Spring4D very very good, at any rate :slight_smile: ]