Delphi: Pitfalls of Anonymous methods and Capture

I was writing a web request handler when I ran into a problem. I was plugging in multiple handlers, but only one of them actually worked.

Why?

To get to the essence of it, this doesn’t work

procedure TMyClass.Setup;
var
  Handler: THandlerClass;
  hType: THandlers;
begin
  Broker.Clear;
  for hType in [foo, bar]
  do begin
    case hType of
      foo: Handler := TFoo.Create;
      bar: Handler := TBar.Create;
    end;
    Broker.AddHandler(Handler.OnHandle);
  end;
end;

Zipped example source code: https://drive.google.com/open?id=1RxOxOlYOrjqPryW7vGNw40VTLav6IN_M

Continue reading “Delphi: Pitfalls of Anonymous methods and Capture”

Delphi Developers Archive (Experimental)

Delphi Developers Archive (Experimental)

 

https://delphi-developers-archive.blogspot.com

 

The posts are searchable by tag list or free text search.

 

FYI – This is work in progress, and I hope to improve the following issues:

– Some posts have erroneous titles

– Some posts are missing attribution of the original poster

– Some 600 posts are missing due to an inexplicable quota error during import

 

Comments on the archived posts are currently disabled until the import is finalized.

We are looking for an experienced Delphi developer for a permanent position in our Industrial IT team at TINE SA,…

We are looking for an experienced Delphi developer for a permanent position in our Industrial IT team at TINE SA, Norway’s largest dairy product company.

About TINE: https://www.tine.no/english

Language and Location requirements

You must be able to speak/read/write Norwegian and English fluently, and be able to work at TINE’s offices at Kalbakken in Oslo.

Coding skills you need

– Modern Delphi OOP code with generics and attributes

– Delphi VCL / Windows APIs / FireDAC

– MS SQL Server T-SQL and SQL queries in general

– Basic http/tcp/udp networking

– XML/JSON knowledge

Coding skills that would be nice

– Delphi FireMonkey on iOS/Android

– MSVS C#/.NET

– MS PowerShell

– HTML5/JS/CSS

Bonus skills that come in handy

– Datawarehousing and big data

– IoT (the buzz, the hype, the stuff that works)

– Knowledge of the various aspects of Logistics and exchanging information between actors (GS1)

– Jira/SVN/git experience

Person skills we really appreciate

– Open and honest and not afraid to speak your mind

– Able to communicate clearly in writing

– Works well with others and can take and give positive feedback

– Willing to learn and adapt, as well as share and mentor

– Able to focus on and prioritize tasks, putting need before cool/fun

You have been programming for a while and can document your experience.

Please send your questions to

lars.fosdal (at) http://tine.no

Please note: Official posting will come later.

I wrote a function to make JSON more readable, and naturally I wonder if I missed something crucial so that it…

I wrote a function to make JSON more readable, and naturally I wonder if I missed something crucial so that it eventually will break?

There are probably more efficient ways to work with strings than concatenating character by character, but performance was not a key goal.

I hereby commit it to public code review 😉

https://pastebin.com/Juks92Y2

Reminder: When you need help, please be specific and remember to tell us:

Reminder: When you need help, please be specific and remember to tell us:

– Version of Delphi incl. ver.no (D5, D2006, XE3, XE8, Seattle 10.0.x, Berlin 10.1.x, Tokyo 10.2.x, etc.)

– SKU (Community, Pro, Enterprise, Architect)

– Platform (Windows, iOS, Android, Linux)

– Tech (console, VCL, FMX, etc)

– Database platform (ADO, dbExpress, FireDAC, etc)

– Database (MSSQL, MySQL, Oracle, SQLite, etc)

Also see: https://plus.google.com/+LarsFosdal/posts/NarwjyzC4rN

Where do you place your unit uses?

Where do you place your unit uses?

Over the years, I’ve come to preferring to place my uses in the Interface section only, even if its types, constants or methods only are used in the implementation section.

What is your practice, and why do you prefer one pattern over the others – or why would you recommend against one of these patterns?

unit Test;

interface

uses

ThisUnit, ThatUnit;

implementation

end.

vs

unit Test;

interface

uses

ThisUnit;

implementation

uses

ThatUnit;

end.