Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 01/29/23 in all areas

  1. I just spent some time testing ChatGPTs ability to "understand" and explain Delphi source code. The results were actually quite good. I asked ChatGPT "what’s wrong with the following Delphi code?" function IsoStringToDateTime(const ISODateTime: string): TDateTime; const ISOShortLen = 19; ISOFullLen = 23; var y, m, d, h, n, s, z: Word; begin // ISODateTime should be in one of these formats: // YYYY-MM-DDTHH:NN:SS, YYYY-MM-DD HH:NN:SS // YYYY-MM-DDTHH:NN:SS.ZZZ, YYYY-MM-DD HH:NN:SS.ZZZ if (Length(ISODateTime) <> ISOShortLen) and (Length(ISODateTime) <> ISOFullLen) then raise EConvertError.Create('Invalid ISO date time string: ' + ISODateTime); y := SysUtils.StrToInt(Copy(ISODateTime, 1, 4)); m := SysUtils.StrToInt(Copy(ISODateTime, 6, 2)); d := SysUtils.StrToInt(Copy(ISODateTime, 9, 2)); h := SysUtils.StrToInt(Copy(ISODateTime, 12, 2)); n := SysUtils.StrToInt(Copy(ISODateTime, 15, 2)); s := SysUtils.StrToInt(Copy(ISODateTime, 18, 2)); z := StrToIntDef(Copy(ISODateTime, 21, 3), 0); // Optional Result := EncodeDate(y, m, d) + EncodeTime(h, n, s, z); end; and also "What does the following Delphi function do?" function FileSizeToHumanReadableString(_FileSize: Int64): string; begin if _FileSize > 5 * OneExbiByte then Result := Format(_('%.2f EiB'), [_FileSize / OneExbiByte]) else if _FileSize > 5 * OnePebiByte then Result := Format(_('%.2f PiB'), [_FileSize / OnePebiByte]) else if _FileSize > 5 * OneTebiByte then Result := Format(_('%.2f TiB'), [_FileSize / OneTebiByte]) else if _FileSize > 5 * OneGibiByte then Result := Format(_('%.2f GiB'), [_FileSize / OneGibiByte]) else if _FileSize > 5 * OneMebiByte then Result := Format(_('%.2f MiB'), [_FileSize / OneMebiByte]) else if _FileSize > 5 * OneKibiByte then Result := Format(_('%.2f KiB'), [_FileSize / OneKibiByte]) else Result := Format(_('%d Bytes'), [_FileSize]); end; The answers will surprise you. And these were the shocking answers. The answers were actually quite interesting.
  2. Patrick PREMARTIN

    Need a "Delphi programming guideline"

    Last year (or previous one, I don't remember), Marco CantΓΉ published the updated release of the "official" Delphi's Object Pascal Style Guide. A good start for a lot of coding choices when you have no rules and are not alone on a project. It's online, you can read it and pick some pages for your colleagues and boss. On the Resources / White papers page of Embarcadero website you have a lot of ebooks and books. One of them is a bible for Delphi Object Pascal developers : Object Pascal Handbook Delphi 11 Alexandria Edition You can also read Code Faster in Delphi to have a lot of coding tips. Put them on the Windows desktop of your colleagues, they must read books about coding and good practices !
  3. esegece

    Recomnended Email and Webserver Components

    If you need to send gmail authentication using OAuth2 you can try this open source project which implements this type of authentication using the Indy components: https://github.com/geoffsmith82/GmailAuthSMTP/blob/master/README.md Additionally, I offer a commercial product called sgcWebSockets that includes support for Indy servers with support for HTTPs with the latest openSSL using a custom library with support for the latest TLS 1.3 (openSSL 1.1.1 and 3.0.0). OAuth2 authentication is also supported on server and client components, Indy IOCP Server for high performance servers... and much more features, you can check in the following link: https://www.esegece.com/websockets Kind Regards, Sergio
  4. Stano

    Summary row at the end of select

    First, you should study the basics of SQL syntax. In the second query, after UNION, you must have GROUP BY. Doesn't DB slap you?
  5. mjustin

    Summary row at the end of select

    The SQL for Query2 must contain a WHERE clause to filter out only the rows for the selected employee ID. Also the GROUP BY can not not work because its SELECT clause does not use aggregate functions. GROUP BY id also makes no sense at all, as ID is the record id in the payment table.
  6. Angus Robertson

    400 Bad Request ,nginx/1.14.0

    WinPCap development ceased a few years again, it was taken over by Npcap which is used by most network sniffing software, including Wireshark which is the leader. I wrote a Delphi sample packet sniffer using WinPCap and Npcap many years ago, very basic really needs better filtering and IPv6 support, must spend some time on it. Angus
  7. Anders Melander

    Skia component and IDE

    WHAT? I DON'T UNDERSTAND YOU. SPEAK LOUDER! I'M A BIT DUMB SO YOU'LL HAVE TO SPEAK REALLY, REALLY SLOW - AND LOUD.
  8. PeterBelow

    KeyDown and Shift state

    Why should it? The Shift parameter is not a Var parameter so you just change the local value of it, not the one the caller passed. Even changing that (if you could) would not do what you think it should since it would not change the Windows-internal state of the modifier keys. And the WM_CHAR message for the tab key is already in the message queue anyway. Using keybd_event (in fact thats deprecated, you should use SendInput instead) puts a completely new Shift-Tab combination into the message queue, so you better set Key := 0 to abort processing of the 37 key. You should use virtual key codes instead of numeric values however, those make it clear which key you are processing here. VK_LEFT is much more readable than 37.
  9. Anders Melander

    KeyDown and Shift state

    You can see from the method signature that Key can be modified (it's passed by reference; as a "var") and that Shift cannot (it's passed by value). We cannot tell if it's "the best way" since you haven't really explained what problem you're solving (see XY problem) - And we cannot predict your future. One thing to be aware of is that keyboard events are read from the message queue in the order in which they occurred. Keybd_Event will append to this queue so you might end up with a key sequence that doesn't correspond to what actually occurred.
  10. programmerdelphi2k

    Need a "Delphi programming guideline"

    take care about your comments here... who knows who can see it? ... a robot, a BOSS... your ex πŸ‘¨β€πŸ­πŸ‘¨β€πŸ­πŸ‘¨β€πŸ­πŸ‘©β€πŸŽ¨
  11. programmerdelphi2k

    Access to Google Calendar via Delphi

    https://www.clevercomponents.com/articles/article038/ "CleverComponents" is paid suite but in Github it can help you start with your code... https://github.com/CleverComponents/Google-Calendar-API
  12. Remy Lebeau

    RttiContext Create and Free

    Since Delphi 2010, actually. RTTI data is pooled in memory. There is only 1 ref-counted copy of the RTTI data in memory that all active TRttiContext instances share. That article is old, and not 100% accurate. For instance, the implementation of TRttiContext.Create() shown in the article is how Create() was implemented in D2010, but it was changed in XE. Test1 is creating and destroying the RTTI pool 100 times, because it only has 1 TRttiContext instance alive at a time. The pool's refcount never goes above 1. The pool is recreated each time the refcount is incremented to 1, and destroyed when the refcount is decremented to 0. That is not the case in Test2, which has 2 active TRttiContext instances alive at a time so the pool is not destroyed until after the loop is finished.
  13. Attila Kovacs

    Summary row at the end of select

    records.... nevermind. spread your spagetticode in comicbooks
Γ—