-
Content Count
3416 -
Joined
-
Last visited
-
Days Won
113
Everything posted by Lars Fosdal
-
Ah, my bad - I didn't notice the MMX context.
-
In the declaration? I usually end up with a recorded macro since I only rarely want a setter procedure.
-
RTTI in dpr / console app dpr
Lars Fosdal replied to Attila Kovacs's topic in RTL and Delphi Object Pascal
Treat console apps like you treat VCL or FMX apps. Keep the actual code in units and have just the skeleton init and run code in the .dpr. -
Typed constants in Delphi.
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
I tested in 10.3.3. -
@Scott - Are you on subscription? In that case you can actually join the Beta testing pool and help unearth these problems. My team usually don't move to a new version until Update 1 is out.
-
Typed constants in Delphi.
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
Heated discussions that end well - No problem, IMO. Discussing in writing is always difficult. Differences such as cultural background and language can make it easy to trip up and come across the wrong way. As long as we are patient and try to stay positive and on the ball instead of the man - there is hope. -
Typed constants in Delphi.
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
You're asking for immutability ... this is hard to achieve on unmanaged system and specially for Delphi (breaking type-system compatibility). I think placing constants on ROM would be much better as it doesn't require changing the system-type language. What do you think ? I think that I really don't care about the underlying implementation detail. I just want truly constant typed constants. It would allow me to write consistent, readable, reusable code and allow array parameters and typed constant parameters for attributes. A minor performance penalty would be acceptable if that goal could be achieved. -
Typed constants in Delphi.
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
Dude, why do you think I wrote And again - I really don't care about the speed penalty. I just want constants that are actual constants also when typed and that cannot be changed at runtime. -
Typed constants in Delphi.
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
Cut'n paste and RX replace. That said: It is unlikely that I'd have more than a few thousand typed record constants. I.e. The increase in compiler time is for all practical purposes insignificant. -
Typed constants in Delphi.
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
You got the source. Be my guest. -
Typed constants in Delphi.
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
That was for 32-bit 64-bit compiler appears to have a tad longer compile time for typed constants. 1.2s vs 0.9s for string consts, but the margins are so small and the variation so large, that it is hard to say. -
Typed constants in Delphi.
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
Overly simple Compilation Speed Test The attached project has a define. {$define AsTyped} When defined, the Texts record contains 500 typed constants. When not defined, the Texts record contains 500 constant strings. On my rather busy laptop, the compile time varies between 0.8 to 1.3s for both with or without the define. TypedConsts2.dpr -
Typed constants in Delphi.
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
My most common use of typed constants is records containing translation strings. These are used for in-place translation of errors and prompts in JsonRPC responses, instead of the typical translated resource solution you would use in a desktop application. This is done to reduce the cost of lookup, since the same server will be required to respond to requests in multiple languages. It works so well that we've started using the same system for configuring text for grids, etc. - just to simplify the process of adding new content without requiring more translation work in a separate tool. For me, the benefits are that the translations are kept in one place - so it is next to impossible to mistranslate a text, or forget about adding a translation in a specific place when adding a new language and since the texts are in the source code, it is trivial to add new translations. I have hundreds of these typed constants and if they do add compile time, it must be next to nothing, because I can't say that I notice any slowdown in the compilation. My main gripe is that I cannot pass these as parameters to an attribute. Here is a simplified albeit rather contrived example but it illustrates my point. program TypedConsts; {$APPTYPE CONSOLE} {$R *.res} uses System.Classes, System.SysUtils, Vcl.Graphics, Generics.Collections; type TxStyle = record font: string; size: integer; attr: TFontStyles; end; type TextStyle = record const // typed consts within a record to create a pseudo namespace Title: TxStyle = ( font: 'Arial'; size: 12; attr: [fsBold]); Chapter: TxStyle = ( font: 'Arial'; size: 10; attr: [fsBold]); Section: TxStyle = ( font: 'Georgia'; size: 10; attr: [fsBold]); Normal: TxStyle = ( font: 'Arial'; size: 9; attr: [fsBold]); Code: TxStyle = ( font: 'Courier New'; size: 9; attr: []); Hint: TxStyle = ( font: 'Garamond'; size: 8; attr: [fsItalic]); OhNoes: TxStyle = ( font: 'Comic Sans MS'; size: 8; attr: [fsItalic]); end; type FontAttribute = class(TCustomAttribute) Style: TxStyle; constructor Create(const aStyle: TxStyle); overload; constructor Create(const aFont: string; const aSize: Integer; aAttr: TFontStyles); overload; end; type TText = class private FText: String; FStyle: TxStyle; published property Text: String read FText write FText; property Style: TxStyle read FStyle write FStyle; end; TParagraphs = TObjectList<TText>; //{$define UseRec} // Define to use the record format, undefine to use the individual fields // Regardless of defined or not, this does not compile. TDoc = class // would have a method to crawl the type RTTI and initialize the style attributes. private FTitle: TText; FBody: TParagraphs; public {$ifdef UseRec} [Font(TextStyle.Title)] {$else} [Font(TextStyle.Title.font, TextStyle.Title.Size, TextStyle.Title.attr)] {$endif} property Title: TText read FTitle write FTitle; {$ifdef UseRec} [Font(TextStyle.Normal)] {$else} [Font(TextStyle.Normal.font, TextStyle.Normal.Size, TextStyle.Normal.attr)] {$endif} property Body: TParagraphs read FBody write FBody; end; { FontAttribute } constructor FontAttribute.Create(const aStyle: TxStyle); begin Style := aStyle; end; constructor FontAttribute.Create(const aFont: string; const aSize: Integer; aAttr: TFontStyles); begin Style.font := aFont; Style.size := aSize; Style.attr := aAttr; end; begin try { TODO -oUser -cConsole Main : Insert code here } except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. -
TIP: How to preview any text file in File Explorer
Lars Fosdal replied to Lars Fosdal's topic in Tips / Blogs / Tutorials / Videos
No tool. Just an entry in the registry per text file extension (.pas .dpr .json etc). -
Byte and Integer
Lars Fosdal replied to Skrim's topic in Algorithms, Data Structures and Class Design
qp is down again 😕 -
Strange behavior for literals
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
For me as purely a Delphi user, the comparison to FPC is irrelevant. -
Strange behavior for literals
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
On the other hand, very few major crises in Delphi development appear to have been caused by unclear constant types. For me, it is a bigger challenge that a typed constant is not regarded as an actual constant. -
Strange behavior for literals
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
-5 shr 63 will always be 1. -
Embarcadero LSP Server for Delphi has stopped working
Lars Fosdal replied to dummzeuch's topic in Delphi IDE and APIs
As always - Make sure the LSP logs, and report the crash on QP with the log attached. -
Strange behavior for literals
Lars Fosdal replied to Mahdi Safsafi's topic in RTL and Delphi Object Pascal
@Kas Ob. Ref second tests: B and G reporting errors is correct. Int64(1) or NativeInt(1) shl 63 are negative numbers, which you cannot assign to an unsigned int. As for D, NativeUInt = 32-bit. Shifting a 1 63 places to the left in a 32-bit variable, should yield 0. -
Any news on TLS 1.3 support? We will be needing it this autumn as the APIs we access will make it a mandatory requirement.
-
Just curious - will changing the loading order of the plugins have any effect?
-
What I did to get my favorite color scheme from 10.3 to 10.4 and have it stick. In 10.4, go to Options | User Interface | Editor | Color With the current colors, just click on [Save As] and and give your personal scheme a name. I called mine Lars. This creates a Registry branch, named HKEY_CURRENT_USER\Software\Embarcadero\BDS\21.0\Editor\Highlight\Custom themes\Lars In RegEdit, go to HKEY_CURRENT_USER\Software\Embarcadero\BDS\20.0\Editor\Highlight (i.e. the Rio branch) Export to a file, f.x. MyColors.reg In MyColors.reg, you'll see Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Embarcadero\BDS\20.0\Editor\Highlight] [HKEY_CURRENT_USER\Software\Embarcadero\BDS\20.0\Editor\Highlight\Additional search match highlight] ... and so on Now, Open MyColors.reg in Notepad, search for "20.0\Editor\Highlight\" and replace it with "21.0\Editor\Highlight\Custom themes\Lars\". Add the two branch paths for good measure. Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Embarcadero\BDS\21.0\Editor\Highlight] [HKEY_CURRENT_USER\Software\Embarcadero\BDS\21.0\Editor\Highlight\Custom themes] [HKEY_CURRENT_USER\Software\Embarcadero\BDS\21.0\Editor\Highlight\Custom themes\Lars] [HKEY_CURRENT_USER\Software\Embarcadero\BDS\21.0\Editor\Highlight\Custom themes\Lars\Additional search match highlight] ... and so on Import the file into the registry, Restart the 10.4, go to Options | User Interface | Editor | Color and pick the custom theme "Lars".
-
Or... add Posix.Unistd to the uses clause in the file where you use DeleteFile.
-
It is. C:\Program Files (x86)\Embarcadero\Studio\20.0\source\rtl\sys\System.SysUtils.pas(1638): function DeleteFile(const FileName: string): Boolean; {$IFDEF POSIX}inline;{$ENDIF}