Jump to content

David Heffernan

Members
  • Content Count

    3709
  • Joined

  • Last visited

  • Days Won

    185

Everything posted by David Heffernan

  1. David Heffernan

    What .PAS file does a form use?

    It could also be TForm and everything assembled at runtime. @Anders Melander already ended all debate in this thread.
  2. David Heffernan

    What .PAS file does a form use?

    You can see your project, we cannot.
  3. David Heffernan

    How do I assert a single ?

    The principle of a function that compares real values for equality, up to a specified tolerance, is a valid thing to do in many cases. But there are lots of caveats. In practise, most developers (and far from just in the Delphi space) that I see recommending it are completely unaware of these caveats. Some of these caveats and issues: How do you choose a tolerance? Does your tolerance account for the scale of the values, and indeed should it? Some use cases demand absolute tolerances, some demand relative tolerances. If you are accounting for scale, how do you choose the scale? Is it based on the pair of values being compared, or should it be based from the total pool of values. For instance, you might have two series that you wish to compare. Shouldn't the scale be based on the series rather than individual samples? Or maybe it is individual samples. It's easy to mistake this as an equality, but the resulting relationship implied by equality to tolerance is not transitive, so is not a mathematical equality. That is a R b and b R c does not imply a R c. Looking more specifically at Delphi's SameValue, the tolerance used when the Epsilon parameter is zero (or omitted) is very odd. I definitely think puppies are dying left, right and centre when that code path is chosen. One of the common misconceptions with floating point is that it is not exact. I think of it as exact, subject to the rules of the domain, but the key point is that not all values are representable. So if you have floating point values a and b, then they represent some precise real value. But when you do a * b, say, then the true value may not be representable. And so the result is the closest representable value. This is well defined, and reproducible. A lot of people think that there's just some random errors and fuzz in it all. That FuzzFactor constant in the RTL source seems to be a classic example of that sort of thinking. This famous question on SO is a useful resource: https://stackoverflow.com/questions/588004/is-floating-point-math-broken One of my pet bug bears in Delphi is its inability to convert correctly between floating point and textual representations. In every other mainstream language (and most non-mainstream languages) this is possible. But in Delphi the code used to perform these conversions is home grown and broken. There are good algorithms for doing this, and it's a subject of active research, but Embarcadero don't seem to care about this. In my codebase I use correct algorithms. Which means that for all values I can convert from float to text and back and always get the same value. The inability to do this often leads to users calling SameValue. My own codebase does call comparison function that compare for equality to tolerance. But there is a lot of care taken in how the tolerance is chosen and applied. I guess that's the crux of what I am saying. So many people just say, this is hard, slap a tolerance onto the comparison that is good enough for the two values I have to hand, and surely that's fine for all other values! I'm a bit of a pedant in this area, I admit. But it's kind of my job to be. Sorry!
  4. David Heffernan

    How do I assert a single ?

    I don't think that the parameter to SameValue should be named either epsilon or delta, it should be tol or tolerance. Or am I misunderstanding?
  5. David Heffernan

    Millisecond Counter

    Yes, my fault. Sorry.
  6. David Heffernan

    Millisecond Counter

    I mean you didn't say any of this in your original post. Clearly you knew what your requirements were, but we can't read your kind!
  7. David Heffernan

    Millisecond Counter

    var Counter: UInt64;
  8. David Heffernan

    restore ansi from utf8

    My advice is to understand a problem before looking for a solution. At the moment it's clear that the problem still eludes you. Concentrate on that first.
  9. David Heffernan

    How do I assert a single ?

    Every time someone calls SameValue a puppy dies
  10. David Heffernan

    How do I assert a single ?

    It depends a bit on what your goals are. But if you want to test equality then you need to put the expected value into a single. That's hard to do in a compiler because delphi literal syntax doesn't allow to specify the type of a floating point literal. You could declare a typed constant of single type and compare against that.
  11. David Heffernan

    access violation changing font

    Before reaching this conclusion, does there exist a clear diagnosis of the problem. That hasn't been shown here yet, so I'd want to understand the problem before trying to solve it.
  12. David Heffernan

    access violation changing font

    This is incorrect. Changing font properties in an event handler is fine.
  13. It has nothing to do with assignment. It's pretty rare for absolute to be useful. Pretend it doesn't exists, and you'll get a long way.
  14. It will never find invalid pointers, but that's not why Assigned exists
  15. I think the use of string here is to allow encoding of indeterminate masses for elements with no stable isotopes, or something along those lines. Look at the items with mass surrounded by parens.
  16. What are you trying to achieve here? As Stefan says, why aren't you declaring these as records to begin with? And why would you want to make anything here a variable. Seems like this area of Physics is pretty much fixed!
  17. David Heffernan

    Anonymous methods as interfaces

    It's the official name for them, as you can see from the documentation https://docwiki.embarcadero.com/RADStudio/en/Anonymous_Methods_in_Delphi
  18. David Heffernan

    Getting Win 11 in Delphi

    We've no idea what your system is. There are many versions of Delphi. We don't know what your app manifest is. These are both possibly relevant.
  19. David Heffernan

    What does [ref] attribute actually dows

    Whether or not you want to use asm is not relevant. It's what you do with it that matters. I mean, exactly what you said above would apply equally if you wanted to write the code in pascal.
  20. David Heffernan

    What does [ref] attribute actually dows

    Why would [ref] be needed to use asm?
  21. David Heffernan

    What does [ref] attribute actually dows

    Is there any known use case other than the one demonstrated by FreeAndNil, namely to allow modification of a const param?
  22. Is there any known use case other than the one demonstrated by FreeAndNil, namely to allow modification of a const param?
  23. David Heffernan

    Delphi 12.3 Patch and McAfee

    McAfee, like so many AV products, the cure is worse than the disease.
  24. David Heffernan

    Ext4 parse

    Isn't this a well documented file system for which there are multiple open source projects that you can use to support the documentation? More generally, I'd advise you to put more effort into asking questions. Time spent describing what your problem is, what you already know, where you are blocked, etc. is effort you should spend if you want to get something in return.
  25. David Heffernan

    Exception not caught

    Doesn't sound like it's not that exceptions aren't handled. App exiting is entirely different. How about the details we asked for.
×