For my link archive: [WayBack] GitHub – pierrejean-coudert/delphi-libraries-list: List of Delphi Libraries and Frameworks
–jeroen
Posted by jpluimers on 2021/01/14
For my link archive: [WayBack] GitHub – pierrejean-coudert/delphi-libraries-list: List of Delphi Libraries and Frameworks
–jeroen
Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »
Posted by jpluimers on 2021/01/13
I think TVirtualMethodInterceptor is a really nice things added to Delphi XE: it allows you to overwrite virtual methods of a class.
Since the documentation from that era cannot be saved in the WayBack machine, here is some more recent documentation:
Over the years, the underlying RTTI has been improved, so it can now do more than in the past, but is still cumbersome to use, see for instance [WayBack] tutorial script delphi Changing component class at run-time on demand – CODE Q&A Solved and [WayBack] TVirtualMethodInterceptor (Delphi) – RAD Studio Code Examples and [WayBack] Entropy Overload: Virtual method interception and [WayBack] Playing around with TVirtualMethodInterceptor | Delphi Haven with TVirtualMethodLogger.
Luckily there are more powerful alternatives based on the same ideas and/or underlying implementationIn fact, it can do so much for instance on the Spring4D and DSharp frameworks.
A demo is at [WayBack] Delphi sorcery: Pimp your unit tests using mock objects or [WayBack] Delphi sorcery: AOP and duck typing in Delphi.
The demo of the mocking framework was at code.google.com/archive/p/delphisorcery, but now is part of bitbucket.org/sglienke/dsharp at bitbucket.org/sglienke/dsharp/src/master/Source/Testing.
Some relevant directories:
Basically it is a playground for the more often updated and stable Spring4D where these directories and files are relevant:
–jeroen
Posted in Delphi, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2021/01/12
A long time ago (Delphi XE2 era), David Dubois and I helped out Doug find either the cause or a workaround of a memory overwrite in a 32-bit application.
The problem was that a call to Format for a pointe or hex value would give corrupt results, but with a regular integer value it would succeed.
Doug created an example [WayBack] overwriting some memory to simulate the problem.
I provided some steps [WayBack] to help trace such cases down.
In the and a rebuild – first withut madExcept, later with madExcept turned on again – solved the problem.
Likely this was the Delphi IDE becoming corrupt, something which I have seen intermittently over the last two decades.
Be sure to read both answers at [WayBack] delphi – Format and Pointers/Hex Values (Memory Overwrite) – Stack Overflow
–jeroen
Posted in Delphi, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2021/01/07
[WayBack] Named Pipes unit for Delphi | Mick’s Mix by Russell Libby, for which (Apr 7, 2013) Francoise Piette has updated this source code for Delphi XE3 and put it on his website at [WayBack] OverByte – Blog Source Code as [WayBack] IpcUsingPipes.zip.
–jeroen
Posted in Delphi, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2021/01/06
A while ago, there was a nice discussion on smart pointers at [WayBack] Smart Pointers – Generics vrs non-generic implementastion – RTL and Delphi Object Pascal – Delphi-PRAXiS [en].
Conclusion from that:
Shared/IShared<T>/TShared<T> from Spring4D has all of the above advantagesThe discussion mentioned above includes both feature and speed comparisons.
I was a bit amazed that at CodeRage 2018, Marco Cantu introduced yet another smart pointer implementation: one worse than existing implementations, and one with only basic demonstration code, leaving out a test suite.
There have many posts on my blog about smart pointers (see the list below), but Spring4D smart pointer implementation has been around for such a long time that any well respected Delphi developer by now should use them. The source is at Shared/IShared (search for {$REGION 'Shared smart pointer'} at the current repository).
This list below on my Smart Pointer related blog posts might not be fully complete, but at least mentions that by now you should be using Spring4D.
IInterface usage.Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development, Spring4D | Leave a Comment »
Posted by jpluimers on 2021/01/05
It looks like there are pages [WayBack] IDEIds21 – RAD Studio … [WayBack] IDEIds21 – RAD Studio.
Maybe I ever find time to find out where they are referenced from and why there is no IDEIds1 page.
–jeroen
Posted in Delphi, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2020/12/31
I like questions like [WayBack] How to check if parent menu item has “checked” child item? – VCL – Delphi-PRAXiS [en]
It means that the asker is closely looking at her or his coding.
This is important, as it helps to get your programming idioms consistent.
The code started out as:
function HasCheckedSubItems(AMenuItem: TMenuItem): Boolean;
var
i: integer;
begin
Result := False;
for i := 0 to AMenuItem.Count - 1 do
if AMenuItem.Items[i].Checked then
Exit(True);
end;
and finally ended up as:
function HasCheckedSubItems(AMenuItem: TMenuItem): Boolean;
var
I: integer;
begin
for I := 0 to AMenuItem.Count - 1 do
if AMenuItem.Items[I].Checked then
Exit(True);
Exit(False);
end;
Which is close to what I’d use, no matter the Delphi version:
function HasCheckedSubItems(const AMenuItem: TMenuItem): Boolean;
var
I: integer;
begin
for I := 0 to AMenuItem.Count - 1 do
if AMenuItem.Items[I].Checked then
begin
Result := True;
Exit;
end;
Result := False;
end;
My argumentation for the last form is that assignment and jumps are too conceptually different to combine in one statement.
The second form moves just one assignment, which on the current scale of nanosecond execution might not sound much, but conceptually limits the assignment to once per function call.
If you are interested in more thoughts on this topic,
–jeroen
Posted in Delphi, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2020/12/30
I bumped into [WayBack] A garbage collector for C and C++ a while ago, for which the source is at [WayBack] GitHub – ivmai/bdwgc: The Boehm-Demers-Weiser conservative C/C++ Garbage Collector (libgc, bdwgc, boehm-gc).
There is a (very old!) wrapper for Delphi too: [WayBack] 21646 API for Boehm Garbage Collector DLL
Barry Kelly <barry_j_kelly@hotmail.com>,
19 April 2004
——————————————————
This archive contains a simple API unit for the Boehm Garbage Collector DLL, along with another unit which makes it easier to use with classes, and a demonstration application. Also included is the Boehm GC DLL binary, along with source code in the gc_dll_src directory.The files:
BoehmGc.pas
———–
This unit exports a dozen or so routines from the Boehm GC dll. Since the GC integrates with and replaces the Delphi default memory manager, you probably don’t need to use this unit unless you want to fine-tune the behaviour of the DLL. The DLL exports more routines than are in this unit; the C prototypes are in the gc_dll_src/gc.h header file, and can be imported as needed. If you allocate large chunks of memory (>100K) which don’t contain references to other chunks (and thus don’t need to be scanned for pointers), there are routines in this unit which you can use to increase performance.General advice: don’t tweak until you need to tweak.
Gc.pas
——
This is the main unit. Put this unit first in the uses clause of you project and the project will automatically use garbage collection. If you want to use objects which require finalization and you don’t want to have to call TObject.Free / TObject.Destroy on them manually, you can use the MarkForFinalization(TObject) function. The basic pattern is to register the object for finalization in its constructor and unregister it with UnmarkForFinalization in its destructor. This handles the two most common use cases for finalization: GC-invoked finalization and manual finalization. Note that it’s always safe to behave as if GC doesn’t exist, and use GetMem/FreeMem, New/Dispose, Create/Free etc. The use of these units simply allows you to also program with garbage collection.GcTest.dpr & GcTest.exe
———————–
This program contains simple sample code demonstrating the garbage collector in action.BoehmGC.dll
———–
This contains the implementation of the garbage collector itself. The DLL can be recompiled from the source in gc_dll_src with various options, including multithreaded support, different pointer alignment granularities, etc.****
The original Boehm GC source comes from: http://www.hpl.hp.com/personal/Hans_Boehm/gc/I’m Barry Kelly: barry_j_kelly@hotmail.com
You can do anything you like with my source code (*.pas, *.dpr).
See the file gc_dll_src/LICENSEa for permissions for the GC itself.
</barry_j_kelly@hotmail.com>
Although when trying to download, I got this for both cc.embarcadero.com/Download.aspx?id=21646 and cc.embarcadero.com/Download.aspx?id=21646&prot=ftp:
Access to the path ‘\\etnaedndb02.embarcadero.com\f\webcache\cc\2004\4\19\21646.zip’ is denied.
An error has occurred while processing the page.
Please try to refresh the page, or return to the home page.
: ETNACDC04
and [WayBack] Jeroen Pluimers auf Twitter: “It looks like the @EmbarcaderoTech code central file cc.embarcadero.com/Item/21646 is broken: “Access to the path ‘\https://t.co/3f3blXN9mp\f\webcache\cc\2004\4\19\https://t.co/0UJUtWvxVV’ is denied.” when exploring or downloading.…”
Explore the files in this upload
File Exploration is Disabled
We’re sorry, but errors in the uploaded zip file prevent it from being explored.
The error generated by the Zip attachment is:
Access to the path ‘\\etnaedndb02.embarcadero.com\f\webcache\cc\2004\4\19\21646.zip’ is denied.You may still be able to repair the zip file contents if you download the entire zip locally. You may also want to ask the author to repost the attachment.
Via [WayBack] delphi – Reference-counting for objects – Stack Overflow which also points to:
Downloads of stable versions: [WayBack] Download · ivmai/bdwgc Wiki · GitHub
–jeroen
Posted in C, C++, Delphi, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2020/12/30
Since I had captures messages inside the main message loop, I forgot it is straightforward: create a [WayBack] TApplicationEvents instance, then use the [WayBack] OnMessage event and hook it to a method like
procedure TMainForm.ApplicationEventsMessage(var Msg: TMsg; var Handled: Boolean); begin // figure out if the TMsg should be handled; set Handled to True if you do not want it to be processed by your application any further // if you do not handle it: bail out as quickly as possible // for performance reasons, it might be wise to have only the decision in this method, and all actual handling (including any managed variables) inside another method. end;
Capturing these messages is limited to the ones processed through the main message loop (or message pump): these are the asynchronous ones either put there by PostMessage or related functions (like PostQuitMessage), or generated by Windows.
This means you will not see any synchronous messages sent to specific Windows using SendMessage.
Unlike the documentation for the OnMessage event, the type inside the method is TMsg from the unit [WayBack]WinApi.Windows, which is an alias for the (documentation mentioned) tagMSG in the same unit; neither type is documented at docs.embarcadero.com or docwiki.embarcadero.com. Luckily, it is documented in the Windows SDK as the structure [WayBack] tagMSG.
That structure is not the same as the [WayBack] TMessage type inside the unit WinApi.Messages [WayBack], as TMessage omits these fields from TMsg:
HWND hwnd;DWORD time;POINT pt;DWORD lPrivate;Luckily the [WayBack] TMessageEvent (that describes the type of the signature of the event method) is better in this regard:
TMessageEvent = procedure (var Msg: TMsg; var Handled: Boolean) of object;
TMessageEventincludes the following parameters:
Msgidentifies the Windows message that triggered the event.Handledindicates whether the event handler responded to the message. If the event handler setsHandledtoTrue, the application assumes that the message has been completely handled and halts any subsequent processing of the message.
TApplicationEvents is actually a multi-cast component (one of the very few multi-casting things parts of the Delphi VCL): an undocumented TMultiCaster class inside the unit Vcl.AppEvnts [WayBack].
A bit reminder though: ALL queued (not sent!) Windows messages flow through this method, so make it as short and efficient as possible, so from the OnMessage documentation:
OnMessageonly receives messages that are posted to the message queue, not those sent directly with the Windows APISendMessagefunction.…
Warning: Caution:Thousands of messages per second flow though this event. Be careful when coding the handler, because it can affect the performance of the entire application.Tip: Call theCancelDispatchmethod from anOnMessageevent handler to prevent the application from forwarding the event to any other application events objects.
TCustomApplicationEvents.CancelDispatch to be documented:Prevents other TCustomApplicationEvents objects from receiving the current event.
A few more relevant links if you want to also hook SendMessage based messages:
Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »
Posted by jpluimers on 2020/12/29
Still relevant, not limited to Delphi, though other environments often have a better warning system in place: [WayBack] Why does my Android application, compiled with Delphi Rio, no longer work?.
TL;DR: over time, Android and the development tools for it, require you to support more recent Android SDK levels.
Those SDK levels come with different requirements than past ones, so when recompiling, you need to check if you fulfill these requirements.
When you don’t, the application is likely to crash, sometimes without any indication why.
Via: [WayBack] Dalija Prasnikar – Google+ /
[WayBack] Dalija Prasnikar on Twitter: “Why does my Android application, compiled with Delphi Rio, no longer work?”
–jeroen
Posted in Android, Delphi, Development, Mobile Development, Software Development | Leave a Comment »