Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 10/26/20 in all areas

  1. Rollo62

    Common callback functions, or not?

    You can change the anon-proc at runtime, if you mean that ... type TAnon = class FParam : Integer; FProc : TProc< Integer >; procedure Setup( AParam : Integer; AProc : TProc< Integer > ); procedure Call; end; ... procedure TAnon.Setup( AParam : Integer; AProc : TProc< Integer > ); begin FParam : AParam; FProc : AProc; end; procedure TAnon.Call; var LInt : Integer; begin LInt := Random( FParam ); if Assigned( FProc ) begin FProc( LInt ); end; end; procedure Test; begin TAnon.Setup( // This are params for the caller 100, // This is called back procedure ( AResult : Integer ) begin Label1.Text := Result: ' + AResult.ToString; end ); TAnon.Call; TAnon.Call; TAnon.Setup( // This are params for the caller 75, // This is called back procedure ( AResult : Integer ) begin Label2.Text := Result: ' + AResult.ToString; end ); TAnon.Call; TAnon.Call; end; Anon procs are especially useful when dealing with async callbacks.
  2. Storing a 31-bit value in a 64-bit intermediary doesn't magically produce more distinct values. You'll still have at most 2^31 distinct values.
  3. Fr0sT.Brutal

    Common callback functions, or not?

    Event handlers and callbacks are more or less the same, I mean event handlers are callbacks (which is more general term). Usually event handlers in follow some additional traditions: - they're procedures not functions and if they return a value, they do it as 'out' parameter - they're optional, that is, an app won't crash if no handler is assigned (though it might do nothing useful then) - most of the time they're called as a reaction to an input or event; often the call chain provides mechanism of cancelling of further process (either by setting a flag of raising EAbort) I use explicit naming as callback when I have an obligatory method that must be assigned and return a value. TGetNameCb = function : string of object; TGreeter = class GetNameCb: TGetNameCb; procedure SayHi; end; procedure TGreeter.SayHi; begin WriteLn('Hi, ', GetNameCb); end; Of course it's just a matter of taste TGetNameEvent = procedure(out aName: string) of object; TGreeter = class GetNameEvent: TGetNameEvent; procedure SayHi; end; procedure TGreeter.SayHi; var Name: string; begin if not Assigned(GetNameEvent) then raise ..; GetNameEvent(Name); WriteLn('Hi, ', Name); end;
  4. dummzeuch

    Detecting update versions in defines

    I know of no such option. GExperts reads the version info of several files to get this info at runtime.
  5. We are glad to announce that StyleControls VCL v. 4.76 is released! http://www.almdev.com StyleControls VCL is a powerful, stable package of components, which uses Classic drawing, system Themes, GDI+ and VCL Styles. This package contains the unique solutions to extend standard VCL controls and also has many unique, advanced controls to create applications with UWP / Fluent UI design. Also with this package you can really improve applying and using of VCL Styles in your application. In new version, we added some functionality and properties that our customers requested.
  6. You are right. The code I posted in this thread is indeed useless. You can't trust RDRAND to return some random values. It was a bad idea. It is never used as unique source of entropy in mORMot. Just as part of a lot of entropy gathering. Here is the documentation of mORMot about the initialization of our cryprographic AES-based PRNG: /// retrieve some entropy bytes from the Operating System // - entropy comes from CryptGenRandom API on Windows, and /dev/urandom or // /dev/random on Linux/POSIX // - this system-supplied entropy is then XORed with the output of a SHA-3 // cryptographic SHAKE-256 generator in XOF mode, of several entropy sources // (timestamp, thread and system information, SynCommons.Random32 function) // unless SystemOnly is TRUE // - depending on the system, entropy may not be true randomness: if you need // some truly random values, use TAESPRNG.Main.FillRandom() or TAESPRNG.Fill() // methods, NOT this class function (which will be much slower, BTW) class function GetEntropy(Len: integer; SystemOnly: boolean=false): RawByteString; virtual; https://github.com/synopse/mORMot/blob/ecc375adc96e5b78d63dd58a88418874a0f622d8/SynCrypto.pas#L1114 And about RDRAND, when mORMot checks the CPUID, it also runs RDRAND and if it fails to return random values, it unset its internal flag, and it will never be used, and not used as entropy. It is even worse on AMD, which can have CF=1 but always return 0 or -1 !!! So in practice, mORMot seems to follow your wise suggestions. My answer in this thread, and my RDRAND use was confusing, for sure. 🙂
  7. Guess what? The new GExperts release is here. There are lots of bug fixes and a few new features in the new version. https://blog.dummzeuch.de/2020/10/23/gexperts-1-3-17-experimental-twm-2020-10-23-released/
  8. Mike Torrettinni

    Common callback functions, or not?

    Oh, Ok, I wasn't sure what you are referring to. But you want the purple icon, right? OK, I just 'thanked you'.
  9. (Low|High)(string) were introduced in XE3, the same version that introduced {$ZEROBASEDSTRINGS} and TStringHelper.
  10. Hi guys, my 4th book "DMVCFramework - the official guide" has been published. Buy it at https://leanpub.com/delphimvcframework For requests, issues and suggestion use https://github.com/danieleteti/dmvcframeworktheofficialguide/issues
  11. Uwe Raabe

    TBytes & TByteDynArray Change in 10.3

    That is correct! With 10.3 there is no difference in TBytes and TByteDynArray. Both are TArray<Byte>. You can simply remove the TByteDynArray overload when compiling for 10.3.
×