What is the difference between the new TFileOpenDialog and the old TOpenDialog?

TOpenDialog executes TFileOpenDialog when the following conditions are met: the program is running under Vista (and up) UseLatestCommonDialogs is true (which is the default) no OnIncludeItem, OnClose or OnShow events are set So while still using TOpenDialog on your system you may likely end up automagically executing TFileOpenDialog in most cases, which explains why they … Read more

How do I sort a generic list using a custom comparer?

The Sort overload you should be using is this one: procedure Sort(const AComparer: IComparer<TMyRecord>); Now, you can create an IComparer<TMyRecord> by calling TComparer<TMyRecord>.Construct. Like this: var Comparison: TComparison<TMyRecord>; …. Comparison := function(const Left, Right: TMyRecord): Integer begin Result := Left.intVal-Right.intVal; end; List.Sort(TComparer<TMyRecord>.Construct(Comparison)); I’ve written the Comparison function as an anonymous method, but you could also … Read more

Why variables are declared as TStrings and created as TStringList?

TStrings is an abstract type that doesn’t have all methods implemented. TStringList is a descendant of TStrings and implements all functions. In your code, you could declare your variable also as TStringList. However e.g. on function definitions it makes sense to accept a TStrings parameter instead of a TStringList: procedure doSomething(lst: TStrings); This enables the … Read more