Jump to content

Lars Fosdal

Administrators
  • Content Count

    3416
  • Joined

  • Last visited

  • Days Won

    113

Everything posted by Lars Fosdal

  1. interface uses REST.JsonReflect, System.RTTI; type TSuppressZeroDateInterceptor = class(TJSONInterceptor) public function StringConverter(Data: TObject; Field: string): string; override; procedure StringReverter(Data: TObject; Field: string; Arg: string); override; end; SuppressZeroDateAttribute = class(JsonReflectAttribute) public constructor Create; end; implementation { TSuppressZeroDateInterceptor } function TSuppressZeroDateInterceptor.StringConverter(Data: TObject; Field: string): string; var ctx: TRTTIContext; date: TDateTime; begin date := ctx.GetType(Data.ClassType).GetField(Field).GetValue(Data).AsType<TDateTime>; if date <= 1.0 then begin result := EmptyStr; end else begin result := DateToISO8601(date, True); end; end; procedure TSuppressZeroDateInterceptor.StringReverter(Data: TObject; Field, Arg: string); var ctx: TRTTIContext; date: TDateTime; begin if Arg.IsEmpty then begin date := 0; end else begin date := ISO8601ToDate(Arg, True); end; ctx.GetType(Data.ClassType).GetField(Field).SetValue(Data, date); end; { SuppressZeroDateAttribute } constructor SuppressZeroDateAttribute.Create; begin inherited Create(ctString, rtString, TSuppressZeroDateInterceptor); end; A trick I learned from @Uwe Raabe : Add the above code somewhere. In your class that emits Json, add the SuppressZeroDate attribute before the Field of the property. TMyClass = class private [SuppressZeroDate] FDate: TDateTime public property Date: TDateTime read FDate write FDate; end;
  2. Lars Fosdal

    Anyone know why?

    As do most of us, but the uncomfortable truth is that work mobility has changed a lot. The younger generations seem to thrive on switching job far more often than the older, who appear to enjoy staying in the same place. And, finding Delphi developers is very hard, as it seems they tend to stay? On relocation - I agree that a lot of work can be done remotely, but even distributed teams do need to get together periodically.
  3. More or less what you write - but as mentioned - the smaller the sample base, the lower the chance of actual working code.
  4. Sounds nice, create request to QC? 🙂 I would, except compiler magic is not a popular subject these days. Also, the corner cases for very short arrays would make it a lot of code for very little gain.
  5. @David Schwartz There is no such thing as 100% perfection. Did you actually read the article - or did you just quote the wrong link? There is nothing about AI being error prone, AI mistakes, or AI immaturity in that article in the quoted link. It is about AI that is proven to work well for code. On another note: I also hear that Co-Pilot X is quite a bit better than the initial Co-pilot. Also - this discussion appear to have two legs - generative AI on the path to general AI (where I disagree) - generative AI applied to code (where I see some benefits, but a lot of pitfalls - particularly for languages with a small sample base) I don't like mundane code or scaffolding either, so I write generic frameworks to minimize that sort of code.
  6. It is nice to have the ability to embellish with color and font size, but I agree - it sucks when people abuse that ability.
  7. Lars Fosdal

    IsNullOrWhiteSpace???

    There is a lot of strange code in that helper. Have a look at function IsEmpty, which compares the string to a record local const Empty - when the unit already has a global constant EmptyStr. Go figure.
  8. Lars Fosdal

    IsNullOrWhiteSpace???

    It could have had a parameterless overload that could be used for the instance. if string.IsNullOrWhiteSpace(s) then Writeln('Yup'); if s.IsNullOrWhiteSpace then Writeln('Yup'); As it is now, only the first construct is supported.
  9. Also, on the term "AI": Uncovered in https://www.bloomberg.com/opinion/articles/2023-03-26/even-with-chat-gpt-4-there-s-no-such-thing-as-artificial-intelligence
  10. Like the latter, yes. Then there is the question of codepage. What if we combine Unicode characters that are not available in the same codepage in the same set of ansi characters? I guess that will fail. AnsiString has codepage declaration support - but AnsiChar does not. Relevant read: Marco's Tech Paper https://www.embarcadero.com/images/dm/technical-papers/delphi-and-unicode-marco-cantu.pdf True - but look at InOpArray. Technically it would be possible to have a in operator that checks if a value exists in an array that would be syntactically identical to value in set. Whether it would be efficient or not with even more compiler magic is questionable.
  11. /on-topic This is application of "AI" in ways that I can like https://visualstudiomagazine.com/articles/2023/03/23/vs-ai.aspx
  12. Interesting. Did they have other plans once upon a time? This means it would be safer with if/then/else structures when testing for Unicode chars. or use var ch: char; begin ch := '€'; if System.WideStrUtils.InOpArray(ch, ['æ', 'ø', '€']) then DebugOut('Yup'); but that is just a sequenctial scan of a widechar array.
  13. /off-topic Me: I need help defusing a bomb AI: What kind of bomb Me: posts a series of photos of the bomb AI: Cut the red wire ... *BOOM* AI: ... after cutting the green wire
  14. The input char is mapped correctly. For keyboards with national keys (f.x. äöæøå etc in Nordic), it at least works correctly. Not sure how it translates source code to AnsiChar, considering that source code can be UTF-8. procedure TestChar; var ch: char; begin ch := '€'; if ch in ['æ', 'ø', '€'] // gives [dcc32 Warning] : W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. then DebugOut('Yup'); end;
  15. https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.SysUtils.CharInSet is the recommended method for checking if a character is in a set. It handles Unicode correctly.
  16. Lars Fosdal

    iOS FMX controls not show on Iphone 14 device with ios 16

    Please make a minimal app that reproduce the problem, and create an issue on https://quality.embarcadero.com Remember to give a good step by step description of how/when it fails.
  17. It seems someone lost their thread...
  18. Lars Fosdal

    Compiling Delphi Apps on Azure DevOps Pileline

    I'd be interested in reading a summary of your findings!
  19. @Rollo62 I think we can say without doubt that none of us wants an AI like the one in the Terminators. I do want AI that is accurate and reliable for the areas that it is applied to.
  20. Lars Fosdal

    Not Threadsafe??

    Threads are not hard, as long as you play by the rules as described by @Dalija Prasnikar There is also good advice in OmniThreadLibrary by @Primož Gabrijelčič
  21. Finding tools for Delphi is not easy. Look at GitHub - out of some 27+ million public repositories, less that 3k are Delphi. Not much material for the AIs to make patterns from. GitHub Advanced Security has no tools that can be directly leveraged for Delphi.
  22. For sure! Who needs an AI to f... things up, when I am perfectly capable of f...ing stuff up myself? 😄
  23. @hsvandrew There is no doubt "AI" (Machine Learning) will impact our work and business systems. What's wrong with me, is that I don't care for a deluge of "My AI generated code doesn't work. Why?" posts.
×