Posts

Just released eBook: Delphi Event-based and Asynchronous Programming

Image
 Delphi Event-based and Asynchronous Programming  I just had to do it... Go with the flow! It's the Black Friday / Cyber Monday "season", so I had to rush the book offer  The book was actually scheduled for release in early December, but then the Black Friday deals started popping up all over the place... pressure was building... and I finally caved in! I cut the darn thing in two, and decided to offer Part I at a discount, and will give Part II for free to all Buyers. Not really a 97% BF discount but hey... Junior is still studying, and we still have to pay the bills (Corona doesn't help, either)! So, here it is!  I hope you'll like it like you did Delphi Memory Management! https://dalija.prasnikar.info/delphiebap/index.html Event-based programming is everywhere. Nowadays, you can hardly write any kind of application without leaning on events and messages. This simple, yet extremely powerful mechanism is also the cornerstone of asynchronous and multithreaded prog

New Book In The Press!

Image
 Delphi Event-based and Asynchronous Programming  About to be released by the end of the month, Delphi Event-based and Asynchronous Programming brings you the following in about 260 pages: Event loops Messaging systems Asynchronous programming Removing Application.ProcessMessages and moving tasks to background threads Threads in general Tasks Futures Thread safety Communicating with the GUI And more... Stay tuned  Just released eBook: Delphi Event-based and Asynchronous Programming

DelphiCon 2020: Windows VCL Panel

Image
Join Ian Barker, Marco Cantù, Alister Christie, Victory Fernandes (Vic), Dr. Holger Flick, David Millington and me at Windows VCL Panel. We will talk about the best Delphi core feature, you all know and love, VCL framework. Scheduled for November 18, 2020, 5:00 pm CET https://delphicon.embarcadero.com/talks/windows-vcl-panel/ DelphiCon 2020. is starting in less than 8 hours. But there is still plenty of time to review the schedule and pick what you like. https://delphicon.embarcadero.com/

Pass the Dog, Get the Cat

This story begins with the FreeAndNil procedure, why its signature could not have a typed var parameter, why we can only pass variables declared as TObject to such procedures, and why the compiler refuses to compile if we try passing any other variable type even if it is a descendant of TObject . procedure FreeAndNil(var Obj); So why does the compiler enforce this behavior? If we take a look at the FreeAndNil implementation and imagine it with a typed var parameter, it may seem that the compiler is throwing us curve balls for nothing. There is nothing we do inside that procedure that would warrant a compiler error for passing TObject descendant types: assigning variable to another TObject variable - pass assigning nil to original variable - pass freeing original object instance stored in temporary variable - pass procedure FreeAndNil(var Obj: TObject); var Temp: TObject; begin Temp := TObject(Obj); Pointer(Obj) := nil; Temp.Free; end; var Obj: TSomeObject

Why some people cannot use dark themes?

Olivier Sannier answers that question in his posts about astigmatism and its impact on everyday software usage: https://www.linkedin.com/pulse/astigmatism-part-1-starry-effects-olivier-sannier/ https://www.linkedin.com/pulse/astigmatism-part-2-blurry-effects-olivier-sannier/ Blog version: https://www.obones.com/en/more/blog/astigmatism-part-1 https://www.obones.com/en/more/blog/astigmatism-part-2 French version: https://www.obones.com/more/blog/astigmatisme-partie-1 https://www.obones.com/more/blog/astigmatisme-partie-2

Magic behind FreeAndNil

Delphi 10.4 Sydney brings one small but rather significant change. A change in the signature of the FreeAndNil procedure from procedure FreeAndNil(var Obj); inline; to procedure FreeAndNil(const [ref] Obj: TObject); inline; Wait, const means the variable is passed as a constant and cannot be changed from within the procedure. But the whole point of FreeAndNil is to change the passed object variable to nil. What kind of sorcery is this? Let's start from the beginning and the old FreeAndNil procedure, its purpose and implementation. The purpose of FreeAndNil is to simplify the following code sequence: Foo.Free; Foo := nil; While the actual implementation of FreeAndNil is slightly different, and it will first nil the reference and then Free the object instance (temporarily preserved in a local variable), that slight difference is not relevant for discussing the signature of FreeAndNil . procedure FreeAndNil(var Obj); var Temp: TObject; begin Temp := TOb

Delphi Nullable with Custom Managed Records

Image
Published with special permission from Embarcadero - this post writes about pre-release Delphi version where everything is subject to change until finally released. Nullables are a rather simple concept. All you need is a value, and some flag that will tell you whether or not the value has been explicitly set or not. type TNullable<T> = record private FHasValue: boolean; FValue: T; function GetValue: T; procedure SetValue(AValue: T); public property HasValue: boolean read FHasValue; property Value: T read GetValue write SetValue; end; function TNullable<T>.GetValue: T; begin if FHasValue then Result := FValue else raise Exception.Create('Invalid operation, Nullable type has no value'); end; procedure TNullable<T>.SetValue(AValue: T); begin FHasValue := True; FValue := AValue; end; Plain and simple. But then you have the fact that records are not automatically initialized and that your FHasValue bo