Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 08/21/24 in all areas

  1. Hi All I created a Delphi implementation of UUIDv7 - RFC 9562 UUIDv7 values are time-sortable, which means you can sort them in increasing order based on when they were generated. https://github.com/VSoftTechnologies/VSoft.UUIDv7 Should work with XE2=12.x Win32/Win64 and all platforms on 11.3 or later. Usage : var guid : TGuid; begin guid := TUUIDv7Helper.CreateV7; writeln(guid.ToString); end;
  2. Anders Melander

    Watch me coding in Delphi on YouTube

    Next up: How to use "with" to make your code more readable.
  3. Stefan Glienke

    Recursive anonymous functions

    To understand this, you need to understand how anonymous methods are implemented. The compiler implements them by creating a class that inherits from TInterfacedObject. The anonymous method type is a special interface with one method called Invoke, which has the signature of the anonymous method type. When you add ReportMemoryLeaksOnShutdown := True to the code above you will see that it reports one instance of a class called MakeFib$ActRec - that is the class name of the compiler-generated class for the anonymous method. The class also contains fields for every captured variable - in this case the local variable fib is being captured with holds the reference to itself so this is the circular interface reference that causes the memory leak. To demonstrate here is the code as the compiler implements it: type MakeFibAnonClass = class(TInterfacedObject, TFunc<integer,int64>) fib: TFunc<integer,int64>; function Invoke(value: integer): int64; end; function MakeFibAnonClass.Invoke(value: integer): int64; begin if value < 3 then Result := 1 else Result := fib(value - 1) + fib(value -2); end; function MakeFib_Impl: TFunc<integer,int64>; var obj: MakeFibAnonClass; begin obj := MakeFibAnonClass.Create; obj.fib := obj; Result := obj.fib; end;
  4. Remy Lebeau

    Recursive anonymous functions

    Inside MakeFib_Impl(), the object reference should be an interface reference instead, to better match what the compiler actually produces: function MakeFib_Impl: TFunc<integer,int64>; var fib: TFunc<integer,int64>; begin fib := MakeFibAnonClass.Create; // refcnt is 1 obj.fib := fib; // refcnt is now 2 Result := fib; end; Although this is a gross oversimplification, as the actual compiler implementation is much more complex (see Variable Binding Mechanism for details). The local fib variable inside of the calling function, and the captured fib variable inside the anonymous method, are actually the same variable in memory. But yes, the self-referencing issue still applies (just on a separate frame object that holds the fib variable). This self-referencing issue is even mentioned in the documentation:
  5. Stefan Glienke

    Watch me coding in Delphi on YouTube

    omg, no! Followed by "How do I fix these random Access Violations that appear in my code"
  6. Dave Nottage

    iOS: Check granted accuracy authorization level

    You can achieve this by writing code that uses CLLocationManager. Create an instance of it, and examine the value of accuracyAuthorization. If it is CLAccuracyAuthorizationReducedAccuracy and your app needs full accuracy, inform the user to: Go to Settings > Privacy & Security > Location Services. Select your app Toggle the Precise Location switch on Example code: uses iOSapi.CoreLocation; procedure TForm1.Button1Click(Sender: TObject); var LManager: CLLocationManager; begin LManager := TCLLocationManager.Create; if LManager.accuracyAuthorization = CLAccuracyAuthorizationReducedAccuracy then // Inform the user end;
  7. silvercoder79

    Watch me coding in Delphi on YouTube

    Setting Up Delphi and RAD Studio for Android Development Link: https://youtu.be/g7tvSlGoG0k In this video, I walk you through the step-by-step process of configuring Delphi RAD Studio for Android development and using the SDK Manager to get the required packages. Along the way, we learn how to overcome common challenges and get your development environment up and running. Useful links: https://en.delphipraxis.net/topic/10436-delphi-120-athens-is-not-correctly-installing-the-android-sdk/ http://delphi.org/2013/10/wireless-android-debugging-with-delphi-xe5/ https://stackoverflow.com/questions/31886049/list-installed-sdk-package-via-command-line
×