Delphi RunTime Library gets enhanced with each new Delphi release, but often these improvements hide behind many flashier features. In this session, you can find out some of these fantastic RTL features.
For instance, you have this Delphi code:
1 2 3 4 |
if value = 0 then Result := 'Zero' else Result := 'Non-Zero'; |
As you can see this is 4 lines of code. You might have seen that in other languages there is a conditional ternary operator. Actually, you can do that thing in Delphi also! How? Here is the solution (be sure to add System.StrUtils unit):
1 |
Result := IfThen(value=0, 'Zero', 'Non-Zero'); |
There you go, this is so easy and efficient.
Here are some of the helpful functions:
- StartsText(const ASubText, AText: String): Boolean;
- RandomFrom(const AValues: Array of String): String;
- MatchText and MatchStr
- DupeString
Be sure to watch the webinar to learn more about these functions in action. You can learn about Parallel Programming Library also!
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
You must take extra precaution when using IfThen(). If statement executes either the “true part” or “else part”,while IfThen() executes both parts. IfThen() functions are inlined, but anyway then pre-evaluate all arguments. Makes a diffference when arguments are function results.
I rewrote a montrosity of a 1000 chars oneliner of 15 nested IfThen() and it was 10x faster.