Jump to content

Lars Fosdal

Administrators
  • Content Count

    3324
  • Joined

  • Last visited

  • Days Won

    110

Everything posted by Lars Fosdal

  1. Wow, I didn't notice that! And it is not related to declaration order, nor ordinal value. That is a bit disturbing.
  2. The inconsistent behavior between the two variations of enumerated types is another pitfall, I guess.
  3. Off-topic - I actually do reverse for in loops with a custom enumerator which starts on top and decrements instead.
  4. @Uwe Raabe Are you saying that for ix := Low(Array) to High(Array) do begin v := Array[ix]; is predictable - while for v in Array is not predictable ?
  5. I wonder how it behaves if I have a set enumerated type with hard coded ordinal values? Edit Change the declaration to TEnum = (plough = 5, foo = 9, bar = 14, wtf = 1); Now the set behaves just like the array.
  6. Except it is rare to see a TList or any other object structure "hardcoded" in plain sight, while arrays of simple types are not hard to read nor uncommon.
  7. For a list or any other object enumeration interface, I'd agree - but for an open array or a TArray?
  8. It is pretty quick to miss that "detail". They look the same, so unless you really pay attention to the type element type - there is little to tell you that you are looking at a set and not a list.
  9. Code that looks correct, and appear to compile alright, but which doesn't execute well. Can you spot the error? See my blog post for a link to a SCCE. var Handler: THandlerClass; hType: THandlers; begin Broker.Clear; for hType in [foo, bar] do begin case hType of foo: Handler := TFoo.Create; bar: Handler := TBar.Create; end; Broker.AddHandler(Handler.OnHandle); end; end; https://larsfosdal.blog/2019/02/08/delphi-pitfalls-of-anonymous-methods-and-capture/
  10. Lars Fosdal

    Pitfalls of Anonymous methods and capture

    Close, its a Self-Contained Compilable Example, sometimes also called a SSCCE, i.e. a Short SCCE. I'll rewrite the article for better readability.
  11. Is this related to databases?
  12. Lars Fosdal

    Pitfalls of Anonymous methods and capture

    There is one, but you "wasn't about to download some project from a file sharing site" (i.e. a zip file with source code from Google Drive)
  13. Lars Fosdal

    Pitfalls of Anonymous methods and capture

    @David Heffernan If you added me to your Ignore list here on DP, I would be totally fine with that.
  14. Lars Fosdal

    Pitfalls of Anonymous methods and capture

    Which is why my post specifically pointed out that there is a link to the SCCE in the blog post?
  15. Lars Fosdal

    Pitfalls of Anonymous methods and capture

    Yes, the examples leak. I didn't want to clutter it up with too much housekeeping code. Thank you, Uwe, for enlightening me on variable vs value capture. IMO, the compiler could need a hint or warning if a variable capture happens in a loop, because it is really easy to overlook. I use a number of variations on this to do dependency injection. It really helps with avoiding pulling too much project specific code into general code and keep the libraries isolated from each other. This code in particular is part of a web server that (now correctly) supports a configurable collection of JsonRPC protocol handlers. The web server knows nothing about Json, and the protocol handlers knows almost nothing about http.
  16. Lars Fosdal

    10.2 Tokyo unable to report issues from within the IDE

    What do we know about the state of 10.3 Rio in this context?
  17. Does anyone know if there are existing libs out there that can extract this across all FMX platforms? - Current user - Device name
  18. Lars Fosdal

    Cross-platform discovery of device name and user name?

    https://developer.android.com/training/id-auth/identify Would this be usable to get some sort of username / identity? Perhaps there is something similar on iOS as well?
  19. Lars Fosdal

    Request for advice: FireMonkey and Frames

    So basically just like for VCL. Nice.
  20. Lars Fosdal

    Request for advice: FireMonkey and Frames

    @Rollo62 Can you exemplify how you "load via runtime into TRectangles" ? In my current app, I want to instantiate the frame onto a TTabItem.
  21. SSD disks are usually connected via SATA (Serial ATA) or PCIe using the NVMe protocol. The first does not do parallel operations, while the second does. However, the speed benefit of the latter is when writing large amounts of data in parallel to individual areas. When deleting files, the OS is rewriting minor amounts of data in a shared area that needs to be integrity managed i.e. shared access locking, so I would suspect that there is no gain to parallelizing deletion of files.
  22. Doh! Never mind! I had commented out one of two overloaded methods in the interface section. There was another "fatal" compilation error further up in the compiler output list. Basically, it was just a weird IDE/compiler artifact due to invalid code.
  23. Lars Fosdal

    TFDParam.Size - best practice?

    I have a new stored proc that takes a varchar(max) argument for logging - and I occasionally run into this problem when the argument is very long. It then raises the following exception EFDException [FireDAC][Phys][ODBC]-345. Data too large for variable [#9]. Max len = [8000], actual len = [24448] Hint: set the TFDParam.Size to a greater value Note that I have a couple of varchar(5000) arguments in the same method that does not complain, so I assume that the default length for strings is 8000 chars. What is the best practice for dealing with this situation? My wrapper code for the stored proc does not really know anything about the potential sizes of these strings as it passes the values as variants. Is it acceptable to always measure the length of the string and dynamically increase TFDParam.size? I have a case already that deals with XML logging to an XML field. vtUnicodeString: begin p.DataType := ftString; s := String(ConstParams[ix].VUnicodeString); len := Length(s) * SizeOf(Char); if Len > p.Size // Autosize then begin p.DataType := ftWideMemo; p.Size := Len + 2; end; p.Value := s; end; But - what happens if the actual field is not type , but [varchar(max)] ? Can I do the above for long string fields? What is the recommended action for handling changes to TFDParam.size for long varchar arguments?
×