For my link archive:
Archive for the ‘Delphi’ Category
.NET: interfaces that inherit from multiple base interfaces
Posted by jpluimers on 2020/12/03
Posted in .NET, C#, Delphi, Development, Software Development | Leave a Comment »
I’m using Delphi XE 10.2: empty documentation tab means you need to update to either the documentation Hotfix or 10.2.3
Posted by jpluimers on 2020/12/03
If you see the Documentation tab like below you need to either:
- install the[WayBack] 10.2.2 Welcome Page and Documentation Hotfix – Community Blogs – Embarcadero Community
- update to 10.2.3
- manually fix the html/CSS width fiddling in
documentation.htm(a name showing the age of the file) as described in [WayBack] Embarcadero Discussion Forums: Tokyio 10.2.2 …
The problem is caused by Embarcadero using mixed technologies in the Delphi IDE combined with their lack of testing due to not eating their own dog-food.
Too bad, as the documentation over the last versions has finally increased after a 10+ year steady decline.
Doing one technology right is hard, but having to mix multiple technologies into one product is extremely hard.
Via: [WayBack] I’m using Delphi XE 10.2. Whenever I click on the Documentation tab, I see the following uselessly rendered page. I can’t seem to resize it either. Anyb… – Graeme Geldenhuys – Google+
–jeroen
Posted in Delphi, Delphi 10.2 Tokyo (Godzilla), Development, Software Development | Leave a Comment »
Delphi spring collections
Posted by jpluimers on 2020/12/02
[WayBack] Spring Collections I have a list of elements, there are, for example, 100 of them. List : IList; I want to get 5 values greater than 10 and … – Jacek Laskowski – Google+
Q
I have a list of elements, there are, for example, 100 of them.
List : IList<Integer>;I want to get 5 values greater than 10 and I do it like this:
result: = List.Where(ValueIsGreatThan10).Take(5);Will the “work loop” be executed a minimum number of times and if, for example, the first 5 values in the list will be greater than 5, then only the five will be checked? Or maybe the
Where()loop will scan 100 elements, andTake()will return the first 5 results?
A (by Stefan Glienke)
WhereandTakeare streaming operators and only execute as much as required.Also the operations have deferred execution. So your statement does not materialize any collection yet. Only if you iterate it will.
They are designed after the operators in .NET so the table from [WayBack] Classification of Standard Query Operators by Manner of Execution (C#) | Microsoft Docs applies. If you find any difference please report it.
Example:
var nums: IEnumerable<Integer>; i: Integer; begin nums := TEnumerable.Range(1, 100).Where( function(const i: Integer): Boolean begin Writeln('checking: ', i); Result := i > 10; end ).Take(5); Writeln('query created'); for i in nums do Writeln('got number: ', i); end.This code will print:
query created checking: 1 checking: 2 checking: 3 checking: 4 checking: 5 checking: 6 checking: 7 checking: 8 checking: 9 checking: 10 checking: 11 got number: 11 checking: 12 got number: 12 checking: 13 got number: 13 checking: 14 got number: 14 checking: 15 got number: 15
–jeroen
Posted in .NET, Delphi, Development, Software Development | Leave a Comment »
Delphi Compiler Intrinsics can help you collapse generated code for generics a lot
Posted by jpluimers on 2020/12/01
On my reading list [WayBack] Delphi Corner Weblog: The current state of generics in Delphi because it explains in more detail why Delphi compiler generic type based intrinsics introduced some 5 years ago, but never been (accurately) documented, but listed at [WayBack] delphi – Undocumented intrinsic routines – Stack Overflow, are so important to help collapse decreasing code bloat:
DefaultIsManagedTypeHasWeakRefGetTypeKind
There is also the TypeInfo which is somewhat documented on-line starting in the Delphi 2007 documentation:
- [WayBack] E2133: TYPEINFO standard function expects a type identifier
- [WayBack] TypInfo.PTypeInfo Type
And some non-generic intrinsics that are still undocumented:
IsConstValueReturnAddress
Spring4D already has been making use of this for a few years, and you can too!
Via [WayBack] rvelthuis.blogspot.com/2018/10/the-current-state-of-generics-in-delphi.html – Jacek Laskowski – Google+ that has some more information on Spring4D too.
A tiny bit more information on collapsing: [WayBack] TURBU Tech » Blog Archive » Wish list: Generics collapsing
–jeroen
Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »
Delphi revelations #3 – kbmMW Smart client – DispInvoke leak – Components4Developers
Posted by jpluimers on 2020/11/26
For my archive, as one day I will run into this Variant/DispInvoke issue myself:[WayBack] Delphi revelations #3 – kbmMW Smart client – DispInvoke leak – Components4Developers:
Delphi revelations, now about investigating a pesky DispInvoke bug in all versions of Delphi supported by kbmMW, including 10.3 Rio, that results in leaks, and how kbmMW now ends up not being affected by it.
Via: [WayBack] Next Delphi revelations, now about investigating a pesky DispInvoke bug in all versions of Delphi supported by kbmMW, including 10.3 Rio, that results i… – Kim Madsen – Google+
–jeroen
Posted in Delphi, Development, Software Development | Leave a Comment »
Delphi: why breakpoints from time to time are not usable (green highlighted line on IDE)? – Stack Overflow
Posted by jpluimers on 2020/11/25
I still have not figured out the circumstances, but ever since either the Unicode Delphi versions (2009 and up) or BDS (8 and up), I have this every now and then: [WayBack] Delphi: why breakpoints from time to time are not usable (green highlighted line on IDE)? – Stack Overflow
So far this is consistent, limiting it to:
- large projects (100+ kilo-lines-of-code)
- for those projects, either as single .dproj file or as part of a .groupproj
- debugging works the first time, but fails consistently with these symptoms:
- break-points fail
- blue dots in the gutter disappear; red-dots become green
- exceptions cause a stack-trace with only hex-addresses
- other projects in the same project group still debug fine
To get it working (one time per try) again:
- restart the IDE
- close the project, then re-open it in the same IDE instance
What does not help getting it to work:
- clean build from the IDE
- deleting DCU files
–jeroen
Posted in Delphi, Development, Software Development | Leave a Comment »
A bunch of Spring4D dependency injection container related questions
Posted by jpluimers on 2020/11/19
Since G+ is down, a lot of interesting questions have vanished.
Luckily I saved some by [WayBack] Jacek Laskowski – Google+ related to Spring4D and dependency injection:
[WayBack] Spring4D IoC and specific singleton… – Jacek Laskowski – Google+
First my Google Groups archival reminder:
- Rename from
- To
- Save that URL with Archive.is
Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »
Do not make methods protected unless you want them to be visible as public
Posted by jpluimers on 2020/11/18
One of the protection levels in Delphi is protected. Originally meant for the class itself, that level is also visible to “friends”: anything in the same unit, for example:
unit BusinessLogicUnit; interface type TBusinessLogic = class(TObject) protected Procedure Foo(); // ... public // ... end; implementation // ... end.
You can even access them from outside that unit by using a trick like below.
Some people use the protected section so that unit tests can assess them using the below trick.
Do not do that!
It means anyone can use that trick, often doing more damage than good.
In this case, the trick was abused by a clever programmer that was relatively new to the code base. It resulted in unintended side effects.
unit HackUnit; interface implementation uses BusinessLogicUnit; type TBusinessLogicHack = class(TBusinessLogic); procedure Hack; var Instance: TBusinessLogicHack; begin Instance := TBusinessLogicHack.Create(); try Instance.Foo(); finally Instance.Free(); end; end; end.
Of course you can still access it like below.
It is slightly longer, but more importantly: much better shows the intent and how that intent is accomplished.
unit GoodUsageUnit; interface implementation uses BusinessLogicUnit; type TBusinessLogicDescendant = class(TBusinessLogic) public procedure Foo(); end; procedure TBusinessLogicDescendant.Foo(); begin inherited Foo(); // ... end; procedure Usage; var Instance: TBusinessLogicDescendant; begin Instance := TBusinessLogicDescendant.Create(); try Instance.Foo(); finally Instance.Free(); end; end; end.
–jeroen
Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | 1 Comment »
The Delphi Geek: Using Generics to Manipulate Enumerated Types
Posted by jpluimers on 2020/11/18
Not that this is bad code, but there are no unit tests for them, and I have seen places in the wild that blindly use it without documenting where it came from and what tested alternatives might be: [WayBack] The Delphi Geek: Using Generics to Manipulate Enumerated Types
The unit itself is down (though there is still a copy on the WayBack machine).
The post itself mentions it is Spring4D-inspired, and since Spring4D already has quite an extensive [WayBack] TEnum<T> implementation covered by unit tests, so that is a logical place to do for.
I might actually document the migration table if I find time for it.
Here is a start so I will only have to insert the blanks
Function Replacement class function Clip(const value: Integer): T; class function Clip(const value: T): T; class function Ensure(const value: Integer; const min, max: T): T; class function Ensure(const value, min, max: T): T; class function FromInt(const value: Integer): T; class function Enum: RangeEnum; static; class function GetValueOrDefault(const value: Integer): T; class function IsValid(const value: Integer): Boolean; class function IsValid(const value: T): Boolean; class function Max: T; static; class function Min: T; static; class function ToInt(const value: T): Integer; class function ToString(const value: T): string;
–jeroen
Posted in Delphi, Development, Software Development | Leave a Comment »
Delphi: `procedure RaiseAbstractError(const aClass: TClass; const aMethodName: string);`
Posted by jpluimers on 2020/11/17
Needs the System.SysConst unit:
procedure RaiseAbstractError(const aClass: TClass; const aMethodName: string); begin // more explanatory than AbstractErrorProc(); raise EAbstractError.CreateFmt('%s: method %s.%s', [SAbstractError, aClass.ClassName, aMethodName]); end;
It uses a TClass typed parameter so you can call it from non-static class methods (using Self as parameter value) in addition to instance methods (using ClassType as parameter value).
–jeroen
Posted in Delphi, Development, Software Development | Leave a Comment »





