-
Content Count
3324 -
Joined
-
Last visited
-
Days Won
110
Posts posted by Lars Fosdal
-
-
2 minutes ago, Stefan Glienke said:Strictly speaking assuming a specific order in a for-in loop is wrong to begin with.
For a list or any other object enumeration interface, I'd agree - but for an open array or a TArray?
-
28 minutes ago, Stefan Glienke said:No I would not because its not a list but a set which are implemented as bitmask and thus have a fixed order.
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.
-
Fresh code: https://github.com/VSoftTechnologies/DUnitX
Typical code that we test with DUnitX:
- value to string and string to value
- lookup functions
- generic classes- formatters
as well as database integration tests (CRUD)
How do you guys use it?
- 2
- 1
-
Not all for loops are created equal.
Consider
for x in [value1, value2, value3]
You would expect to see x vary in the order of the values in the list. However – if x and the values are of an enumerated type, looping the “list” does NOT loop in the apparent order of the constant, but in the order of the enumerated type declaration, such as it would for any set.Example at: https://larsfosdal.blog/2019/02/18/delphi-pitfalls-enumerated-types-and-for-loops/
-
6 hours ago, Rudy Velthuis said:Ok, sometimes (yeah, right, funny) I am dense, but what is SCCE? Source Code Compilable Example?
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.
-
Is this related to databases?
-
15 hours ago, David Heffernan said:I'd still see all the replies. It's an interesting topic that you raised but it needs a clearer example to bring out the issue.
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)
-
-
16 hours ago, David Heffernan said:If we have no knowledge of the types involved in this code then for sure we can't know what's wrong with it.
Which is why my post specifically pointed out that there is a link to the SCCE in the blog post?
-
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.
- 1
-
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/ -
What do we know about the state of 10.3 Rio in this context?
-
Anybody else see the same?
-
https://developer.android.com/training/id-auth/identify
Quote3. Retrieve a built-in account from AccountManager
Would this be usable to get some sort of username / identity?
Perhaps there is something similar on iOS as well?
-
Does anyone know if there are existing libs out there that can extract this across all FMX platforms?
- Current user
- Device name
-
So basically just like for VCL. Nice.
-
@Rollo62 Can you exemplify how you "load via runtime into TRectangles" ?
In my current app, I want to instantiate the frame onto a TTabItem.
-
When creating frames runtime in VCL, there are a set of tweaks that need to be applied to make the frame behave properly after creation (setting parent/owner etc).
Are there similar tricks needed for FireMonkey, and are there other pitfalls related to dynamically creating frames at runtime?
Is it better to drop the frames on the main form at design time?
- 1
- 1
-
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.
-
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.
-
[dcc32 Fatal Error] One.OfMyUnits.pas(1686): E2158 System unit out of date or corrupted: missing '@Clr'
Clean / Build does not fix it. And - it happens on our build server too!
Have any of you seen this one before?
-
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 valueNote 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?
-
I love how responsive TMS are as a company, but I wish they did more regression tests on the TAdvStringGrid.
- 3
-
The official recruitment ad is now out (in Norwegian)
https://www.finn.no/job/fulltime/ad.html?finnkode=137676747
Delphi pitfalls: Enumerated types and for loops
in RTL and Delphi Object Pascal
Posted
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.