Jump to content

Lars Fosdal

Administrators
  • Content Count

    3416
  • Joined

  • Last visited

  • Days Won

    113

Everything posted by Lars Fosdal

  1. Lars Fosdal

    Convert to Property

    Ah, my bad - I didn't notice the MMX context.
  2. Lars Fosdal

    Convert to Property

    In the declaration? I usually end up with a recorded macro since I only rarely want a setter procedure.
  3. Lars Fosdal

    RTTI in dpr / console app dpr

    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.
  4. Lars Fosdal

    Typed constants in Delphi.

    I tested in 10.3.3.
  5. Lars Fosdal

    Your RAD Studio 10.4 Sydney issues

    @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.
  6. Lars Fosdal

    Typed constants in Delphi.

    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.
  7. Lars Fosdal

    Typed constants in Delphi.

    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.
  8. Lars Fosdal

    Typed constants in Delphi.

    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.
  9. Lars Fosdal

    Typed constants in Delphi.

    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.
  10. Lars Fosdal

    Typed constants in Delphi.

    You got the source. Be my guest.
  11. Lars Fosdal

    Typed constants in Delphi.

    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.
  12. Lars Fosdal

    Typed constants in Delphi.

    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
  13. Lars Fosdal

    Typed constants in Delphi.

    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.
  14. No tool. Just an entry in the registry per text file extension (.pas .dpr .json etc).
  15. Lars Fosdal

    Byte and Integer

    qp is down again 😕
  16. Lars Fosdal

    Strange behavior for literals

    For me as purely a Delphi user, the comparison to FPC is irrelevant.
  17. Lars Fosdal

    Strange behavior for literals

    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.
  18. Lars Fosdal

    Strange behavior for literals

    -5 shr 63 will always be 1.
  19. As always - Make sure the LSP logs, and report the crash on QP with the log attached.
  20. Lars Fosdal

    Strange behavior for literals

    @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.
  21. Lars Fosdal

    Indy & OpenSSL 1.1.1 & TLS 1.3

    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.
  22. Lars Fosdal

    Crash when Delphi 10.n exits... again

    Just curious - will changing the loading order of the plugins have any effect?
  23. Lars Fosdal

    Your RAD Studio 10.4 Sydney issues

    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".
  24. Lars Fosdal

    DeleteFile Compilation Message

    Or... add Posix.Unistd to the uses clause in the file where you use DeleteFile.
  25. Lars Fosdal

    DeleteFile Compilation Message

    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}
×