Why are TGeneric and TGeneric incompatible types?

TDataProviderThread is a descendant of TThreadBase, but TThreadBaseList<TDataProviderThread> is not a descendant of TThreadBaseList<TThreadBase>. That’s not inheritance, it’s called covariance, and though it seems intuitively like the same thing, it isn’t and it has to be supported separately. At the moment, Delphi doesn’t support it, though hopefully it will in a future release. Here’s the … Read more

Randomize StringList

One common algorithm to perform a shuffle is the Fisher-Yates shuffle. This generates uniformly distributed permutations. To implement on a Delphi TStrings object you can use this: procedure Shuffle(Strings: TStrings); var i: Integer; begin for i := Strings.Count-1 downto 1 do Strings.Exchange(i, Random(i+1)); end; Now, whilst in theory this will generate uniformly distributed permutations, the … Read more

Delphi event handling, how to create own event

Here’s a short-but-complete console application that shows how to create your own event in Delphi. Includes everything from type declaration to calling the event. Read the comments in the code to understand what’s going on. program Project23; {$APPTYPE CONSOLE} uses SysUtils; type // Declare an event type. It looks allot like a normal method declaration … Read more

How to get a stack trace from FastMM

The internal Delphi version of FastMM doesn’t support stack traces. If you want to log the memory leak stack traces, you have to: download the full version of the FastMM library include it as the first unit in your project: program YourProject; uses FastMM4, // <– SysUtils, Forms, … enable the FullDebugMode option in FastMM4Options.inc … Read more

Delphi, How to get all local IPs?

in indy 9, there is a unit IdStack, with the class TIdStack fStack := TIdStack.CreateStack; try edit.caption := fStack.LocalAddress; //the first address i believe ComboBox1.Items.Assign(fStack.LocalAddresses); //all the address’ finally freeandnil(fStack); end; works great 🙂 from Remy Lebeau’s Comment The same exists in Indy 10, but the code is a little different: TIdStack.IncUsage; try GStack.AddLocalAddressesToList(ComboBox1.Items); Edit.Caption … Read more