Jump to content

David Heffernan

Members
  • Content Count

    3494
  • Joined

  • Last visited

  • Days Won

    172

Everything posted by David Heffernan

  1. David Heffernan

    generics

    An array is a container, but that TArray isn't an array, it's a class containing a lot of static methods.
  2. David Heffernan

    generics

    Yes, nested types. Really just a type declared in the lexical scope of the containing type. Delphi syntax for anonymous methods.
  3. David Heffernan

    generics

    I don't really see anything that is what I would describe as a container / collection.
  4. David Heffernan

    generics

    From my code base I find this: TThreadsafe<T> = class private FLock: TCriticalSection; FValue: T; function GetValue: T; procedure SetValue(const NewValue: T); public constructor Create; destructor Destroy; override; property Value: T read GetValue write SetValue; end; And this: Enum<T: record> = class strict private class function TypeInfo: PTypeInfo; static; class function TypeData: PTypeData; static; public class function IsEnum: Boolean; static; class function Count: Integer; static; class function ToOrdinal(Value: T): Integer; static; class function FromOrdinal(Value: Integer): T; static; class function TryFromOrdinal(Value: Integer; out Enum: T): Boolean; static; class function ToString(Value: T): string; static; class function FromString(const Value: string): T; static; class function MinValue: Integer; static; class function MaxValue: Integer; static; class function InRange(Value: Integer): Boolean; static; class function EnsureRange(Value: Integer): Integer; static; class function FromName(const Name: string): T; static; class function TryFromName(const Name: string; out Enum: T): Boolean; static; class function ToName(Item: T): string; static; class function ToNewSentenceName(Item: T): string; static; class function ToMidSentenceName(Item: T): string; static; class function ToUpperCaseName(Item: T): string; static; class function ToPascalCaseName(Item: T): string; static; end; And this: TArray = class public type TWriteItem<T> = reference to procedure(const TaggedFile: ITaggedFile; const Item: T); TReadItem<T> = reference to procedure(const TaggedFile: ITaggedFile; out Item: T); strict private const SortOrderFactor: array [TSortOrder] of Integer = (1, -1); public class procedure Swap<T>(var Left, Right: T); static; class procedure Reverse<T>(var Values: array of T; Index, Count: Integer); overload; static; class procedure Reverse<T>(var Values: array of T); overload; static; class function Reversed<T>(const Values: array of T): TArray<T>; static; class procedure Shuffle<T>(var Values: array of T; const Random: TFunc<Integer, Integer>; Index, Count: Integer); overload; static; class procedure Shuffle<T>(var Values: array of T; const Random: TFunc<Integer, Integer>); overload; static; class function Contains<T>(const Values: array of T; const Item: T; const Comparer: IEqualityComparer<T>; Index, Count: Integer; out ItemIndex: Integer): Boolean; overload; static; class function Contains<T>(const Values: array of T; const Item: T; const Comparer: IEqualityComparer<T>; out ItemIndex: Integer): Boolean; overload; static; class function Contains<T>(const Values: array of T; const Item: T; const Comparer: IEqualityComparer<T>; Index, Count: Integer): Boolean; overload; static; class function Contains<T>(const Values: array of T; const Item: T; const Comparer: IEqualityComparer<T>): Boolean; overload; static; class function Contains<T>(const Values: array of T; const Item: T; EqualOp: TEqualOp<T>; Index, Count: Integer; out ItemIndex: Integer): Boolean; overload; static; class function Contains<T>(const Values: array of T; const Item: T; EqualOp: TEqualOp<T>; out ItemIndex: Integer): Boolean; overload; static; class function Contains<T>(const Values: array of T; const Item: T; EqualOp: TEqualOp<T>; Index, Count: Integer): Boolean; overload; static; class function Contains<T>(const Values: array of T; const Item: T; EqualOp: TEqualOp<T>): Boolean; overload; static; class function Contains<T>(const Values: array of T; const Item: T; Index, Count: Integer; out ItemIndex: Integer): Boolean; overload; static; class function Contains<T>(const Values: array of T; const Item: T; out ItemIndex: Integer): Boolean; overload; static; class function Contains<T>(const Values: array of T; const Item: T; Index, Count: Integer): Boolean; overload; static; class function Contains<T>(const Values: array of T; const Item: T): Boolean; overload; static; class function Matches<T>(const Values: array of T; const Predicate: TPredicate<T>; out ItemIndex: Integer): Boolean; overload; static; class function Matches<T>(const Values: array of T; const Predicate: TPredicate<T>): Boolean; overload; static; class function Matches<T>(const Values: array of T; const Predicate: TPredicateOfObj<T>; out ItemIndex: Integer): Boolean; overload; static; class function Matches<T>(const Values: array of T; const Predicate: TPredicateOfObj<T>): Boolean; overload; static; class function IndexOf<T>(const Values: array of T; const Item: T; const Comparer: IEqualityComparer<T>; Index, Count: Integer): Integer; overload; static; class function IndexOf<T>(const Values: array of T; const Item: T; const Comparer: IEqualityComparer<T>): Integer; overload; static; class function IndexOf<T>(const Values: array of T; const Item: T; EqualOp: TEqualOp<T>; Index, Count: Integer): Integer; overload; static; class function IndexOf<T>(const Values: array of T; const Item: T; EqualOp: TEqualOp<T>): Integer; overload; static; class function IndexOf<T>(const Values: array of T; const Item: T; Index, Count: Integer): Integer; overload; static; class function IndexOf<T>(const Values: array of T; const Item: T): Integer; overload; static; class function Equal<T>(const lhs, rhs: array of T; const Comparer: IEqualityComparer<T>): Boolean; overload; static; class function Equal<T>(const lhs, rhs: array of T; EqualOp: TEqualOp<T>): Boolean; overload; static; class function Equal<T>(const lhs, rhs: array of T): Boolean; overload; static; class function Ordered<T>(const Values: array of T; const Comparer: IComparer<T>; Index, Count: Integer): Boolean; overload; static; class function Ordered<T>(const Values: array of T; const Comparer: IComparer<T>): Boolean; overload; static; class function Ordered<T>(const Values: array of T; const Comparison: TComparison<T>; Index, Count: Integer): Boolean; overload; static; class function Ordered<T>(const Values: array of T; const Comparison: TComparison<T>): Boolean; overload; static; class function Ordered<T>(const Values: array of T; Index, Count: Integer): Boolean; overload; static; class function Ordered<T>(const Values: array of T): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T; const Comparer: IEqualityComparer<T>; out Value: T; Index, Count: Integer): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T; const Comparer: IEqualityComparer<T>; out Value: T): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T; EqualOp: TEqualOp<T>; out Value: T; Index, Count: Integer): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T; EqualOp: TEqualOp<T>; out Value: T): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T; out Value: T; Index, Count: Integer): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T; out Value: T): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T; const Comparer: IComparer<T>; out Value: T; Index, Count: Integer): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T; const Comparer: IComparer<T>; out Value: T): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T; const Comparison: TComparison<T>; out Value: T; Index, Count: Integer): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T; const Comparison: TComparison<T>; out Value: T): Boolean; overload; static; class function HasDuplicates<T>(const Values: array of T; const Comparison: TComparison<T>): Boolean; overload; static; class function RemoveDuplicates<T>(var Values: array of T; const Comparer: IEqualityComparer<T>; Index, Count: Integer; const Dispose: TProcOfObj<T>): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T; const Comparer: IEqualityComparer<T>; Index, Count: Integer): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T; const Comparer: IEqualityComparer<T>): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T; EqualOp: TEqualOp<T>; Index, Count: Integer; const Dispose: TProcOfObj<T>): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T; EqualOp: TEqualOp<T>; Index, Count: Integer): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T; EqualOp: TEqualOp<T>): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T; const Comparer: IComparer<T>; Index, Count: Integer; const Dispose: TProcOfObj<T>): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T; const Comparer: IComparer<T>; Index, Count: Integer): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T; const Comparer: IComparer<T>): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T; const Comparison: TComparison<T>; Index, Count: Integer): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T; const Comparison: TComparison<T>): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T; Index, Count: Integer): Integer; overload; static; class function RemoveDuplicates<T>(var Values: array of T): Integer; overload; static; class function Sorted<T>(const Values: array of T; const Comparer: IComparer<T>; Order: TSortOrder; Index, Count: Integer): Boolean; overload; static; class function Sorted<T>(const Values: array of T; const Comparer: IComparer<T>; Index, Count: Integer): Boolean; overload; static; class function Sorted<T>(const Values: array of T; const Comparer: IComparer<T>; Order: TSortOrder): Boolean; overload; static; class function Sorted<T>(const Values: array of T; const Comparer: IComparer<T>): Boolean; overload; static; class function Sorted<T>(const Values: array of T; const Comparison: TComparison<T>; Order: TSortOrder; Index, Count: Integer): Boolean; overload; static; class function Sorted<T>(const Values: array of T; const Comparison: TComparison<T>; Index, Count: Integer): Boolean; overload; static; class function Sorted<T>(const Values: array of T; const Comparison: TComparison<T>; Order: TSortOrder): Boolean; overload; static; class function Sorted<T>(const Values: array of T; const Comparison: TComparison<T>): Boolean; overload; static; class function Sorted<T>(const Values: array of T; Order: TSortOrder; Index, Count: Integer): Boolean; overload; static; class function Sorted<T>(const Values: array of T; Index, Count: Integer): Boolean; overload; static; class function Sorted<T>(const Values: array of T; Order: TSortOrder): Boolean; overload; static; class function Sorted<T>(const Values: array of T): Boolean; overload; static; class procedure Sort<T>(var Values: array of T; const Comparer: IComparer<T>; Order: TSortOrder; Index, Count: Integer); overload; static; class procedure Sort<T>(var Values: array of T; const Comparer: IComparer<T>; Index, Count: Integer); overload; static; class procedure Sort<T>(var Values: array of T; const Comparer: IComparer<T>; Order: TSortOrder); overload; static; class procedure Sort<T>(var Values: array of T; const Comparer: IComparer<T>); overload; static; class procedure Sort<T>(var Values: array of T; const Comparison: TComparison<T>; Order: TSortOrder; Index, Count: Integer); overload; static; class procedure Sort<T>(var Values: array of T; const Comparison: TComparison<T>; Index, Count: Integer); overload; static; class procedure Sort<T>(var Values: array of T; const Comparison: TComparison<T>; Order: TSortOrder); overload; static; class procedure Sort<T>(var Values: array of T; const Comparison: TComparison<T>); overload; static; class procedure Sort<T>(var Values: array of T; Order: TSortOrder; Index, Count: Integer); overload; static; class procedure Sort<T>(var Values: array of T; Index, Count: Integer); overload; static; class procedure Sort<T>(var Values: array of T; Order: TSortOrder); overload; static; class procedure Sort<T>(var Values: array of T); overload; static; class function Copy<T>(const Source: array of T; Index, Count: Integer): TArray<T>; overload; static; class function Copy<T>(const Source: array of T): TArray<T>; overload; static; class procedure Move<T>(const Source: array of T; var Dest: array of T; Index, Count: Integer); overload; static; class procedure Move<T>(const Source: array of T; var Dest: array of T); overload; static; class function Concatenated<T>(const Source1, Source2: array of T): TArray<T>; overload; static; class function Concatenated<T>(const Source: array of TArray<T>): TArray<T>; overload; static; class procedure Initialise<T>(var Values: array of T; const Value: T); static; class function New<T>(Count: Integer; const Value: T): TArray<T>; static; class function Zero<T>(Count: Integer): TArray<T>; static; class procedure Zeroise<T>(var Values: array of T); static; class procedure Free<T: class>(const Values: array of T); static; class procedure FreeAndNil<T: class>(var Values: array of T); static; class function GetHashCode<T>(const Values: array of T; const Comparer: IEqualityComparer<T>): Integer; overload; static; class function GetHashCode<T>(const Values: array of T): Integer; overload; static; class function GetHashCode<T>(Values: Pointer; Count: Integer; const Comparer: IEqualityComparer<T>): Integer; overload; static; class function GetHashCode<T>(Values: Pointer; Count: Integer): Integer; overload; static; class procedure Write<T>(const TaggedFile: ITaggedFile; const WriteItem: TWriteItem<T>; const Values: TArray<T>); overload; static; class procedure Write<T>(const TaggedFile: ITaggedFile; const Values: TArray<T>); overload; static; class procedure Read<T>(const TaggedFile: ITaggedFile; const ReadItem: TReadItem<T>; out Values: TArray<T>); overload; static; class procedure Read<T>(const TaggedFile: ITaggedFile; out Values: TArray<T>); overload; static; class procedure Skip(const TaggedFile: ITaggedFile); static; end; And this: NDArray<T> = record public type {$POINTERMATH ON} P = ^T; {$POINTERMATH OFF} private type TEnumerator = record private FOwner: ^NDArray<T>; FCurrentIndices: TArray<Integer>; function GetCurrent: T; public class function New(const Owner: NDArray<T>): TEnumerator; static; property Current: T read GetCurrent; function MoveNext: Boolean; end; private FBase: P; FValues: TArray<T>; FRank: Integer; FShape: TArray<Integer>; FStride: TArray<NativeInt>; function LinearIndex(const Indices: array of Integer): NativeInt; function GetCount: NativeInt; function GetItem(const Indices: array of Integer): T; procedure SetItem(const Indices: array of Integer; const Value: T); function GetSlice(const Indices: array of Integer): NDArray<T>; procedure SetSlice(const Indices: array of Integer; const Value: NDArray<T>); function GetIsEmpty: Boolean; function GetHasZeroDimension: Boolean; public class function New(const Shape: array of Integer): NDArray<T>; overload; static; class function New(const Shape: array of Integer; const Values: TArray<T>): NDArray<T>; overload; static; class function New(const Shape: array of Integer; const Value: T): NDArray<T>; overload; static; class function Zero(const Shape: array of Integer): NDArray<T>; static; class function Diagonal(const Values: array of T): NDArray<T>; overload; static; class function Diagonal(Size: Integer; const Value: T): NDArray<T>; overload; static; class function Empty: NDArray<T>; static; class operator Explicit(const arr: TArray<T>): NDArray<T>; property IsEmpty: Boolean read GetIsEmpty; property HasZeroDimension: Boolean read GetHasZeroDimension; property Rank: Integer read FRank; property Shape: TArray<Integer> read FShape; property Stride: TArray<NativeInt> read FStride; property Count: NativeInt read GetCount; property DataPtr: P read FBase; property Items[const Indices: array of Integer]: T read GetItem write SetItem; default; function ItemPtr(const Indices: array of Integer): P; property Slice[const Indices: array of Integer]: NDArray<T> read GetSlice write SetSlice; procedure CopyTo(Dest: P; Count: NativeInt); function Clone: NDArray<T>; function ToFlattenedArray: TArray<T>; class procedure Write(const TaggedFile: ITaggedFile; const WriteItem: TArray.TWriteItem<T>; const Value: NDArray<T>); overload; static; class procedure Write(const TaggedFile: ITaggedFile; const Value: NDArray<T>); overload; static; class procedure Read(const TaggedFile: ITaggedFile; const ReadItem: TArray.TReadItem<T>; out Value: NDArray<T>); overload; static; class procedure Read(const TaggedFile: ITaggedFile; out Value: NDArray<T>); overload; static; public function GetEnumerator: TEnumerator; end; And this: TIterativeSolver<T> = class public type P = ^T; protected class procedure AGSIterate(A, b, x, work: P; N: Integer; Storage: TMatrixStorage); static; class procedure AGSCalcResidual(A, b, x, r: P; N: Integer; Storage: TMatrixStorage); static; class function AGSIsZero(b: P; N: Integer): Boolean; static; class function AGSSqrMag(x: P; N: Integer): Double; static; class function AGSAccel(r, x: P; work: Pointer; iter, N: Integer): Boolean; static; public class function SolveAGS(const A: NDArray<T>; var b: NDArray<T>; maxiter: Integer; tol: Double; out iter: Integer): Boolean; static; end; And this: type TLUSolver<T> = class public type P = ^T; TWorkspace = record public ipiv: TArray<Integer>; public procedure Update(N: Integer); end; protected //protected to avoid spurious compiler warning class procedure DecomposeDense(A: P; ipiv: PInteger; N: Integer); overload; static; class procedure SubstituteDense(A: P; ipiv: PInteger; N: Integer; b: P; Storage: TMatrixStorage); static; class procedure DecomposeBanded(A: P; ipiv: PInteger; N, Bandwidth, ldab: Integer); overload; static; class procedure SubstituteBanded(A: P; ipiv: PInteger; N, Bandwidth, ldab: Integer; b: P; Storage: TMatrixStorage); static; class procedure DecomposeDense(A: P; N: Integer; var Workspace: TWorkspace); overload; static; class procedure DecomposeBanded(A: P; N, Bandwidth, ldab: Integer; var Workspace: TWorkspace); overload; static; public class procedure Decompose(var A: NDArray<T>; var Workspace: TWorkspace); static; class procedure Substitute(var A, b: NDArray<T>; const Workspace: TWorkspace); static; class procedure Solve(var A, b: NDArray<T>); static; end; And this: TData<T> = record x: T; xPrime: TArray<T>; xPrimePrime: TArray<TArray<T>>; xPrimePrimePrime: TArray<TArray<TArray<T>>>; end; And this: TTableItem<T: TModelObject> = record public ModelObject: T; ObjectIndex: Integer; ItemIndex: Integer; public class function New(ModelObject: T; ObjectIndex, ItemIndex: Integer): TTableItem<T>; static; class function DisplayName(ModelObject: TModelObject; const ItemName: string; ItemIndex: Integer): string; overload; static; function DisplayName(const ItemName: string): string; overload; procedure RedirectDataAccess(var Handler: TDataObject; var Index: Integer); end; I could go on, but it's pretty boring. And these are just some examples from one particular code base. Other code bases will have different use cases. As Stefan said, generics are used for generic programming. So yeah, a myriad.
  5. David Heffernan

    generics

    Apart from the myriad of other applications that aren't about containers
  6. David Heffernan

    ExtractFilePath v TDirectory.GetCurrentDirectory

    This can only be true if you are the only person ever to run your program. These two things, the directory containing the executable and the working directory are completely different and unrelated things. Generally you don't want to use the working directory in a GUI program. It's really only useful in a console app where you can think of the working directory as one of the inputs to the process. What problem are you actually trying to solve?
  7. David Heffernan

    Percent Calculations

    But why? If you are mapping 0..255 to 0.100 why not have the scroll bar range 0..100?
  8. David Heffernan

    Percent Calculations

    Why did you decide to have the scrollbar be ranged between 0 and 255?
  9. David Heffernan

    Corean write in explorer popup menu

    What part of the code or the software on your machine results in this behaviour. Remember that all we know is what you wrote above.
  10. David Heffernan

    NetGroupGetUsers strange errors on Win64 on buffered reads

    I though we were talking about the cause of the access violations in your code. But if I've misunderstood, I'm sorry.
  11. David Heffernan

    NetGroupGetUsers strange errors on Win64 on buffered reads

    It's not going to be a defect in Windows. It's going to be a defect in the code you are compiling. That is your starting mindset. Perhaps somebody else wants to debug your large and complex code. But if you made a minimal reproduction and posted it here I'd expect a better chance of engagement.
  12. David Heffernan

    NetGroupGetUsers strange errors on Win64 on buffered reads

    ResumeHandle should be PDWORD_PTR. Probably other types are declared incorrectly. Check all declarations against the header files. Ask yourself which is more likely. Is it a bug in your code, or a bug in the Windows code?
  13. David Heffernan

    NetGroupGetUsers strange errors on Win64 on buffered reads

    Would be nice to look at code directly in the post rather than have to download some ZIP file
  14. It's probably XP. Cant you get a computer fit for 2022?
  15. David Heffernan

    TopCode Java Library in Delphi

    Extremely hard to tell what is happening here with two seemingly unrelated screenshots.
  16. David Heffernan

    Turbo SynEdit & Font Ligatures

    Not supported by the IDE
  17. This is pretty odd. Times have changed. Visual Studio is a great IDE. There are lots of tools and IDEs that are good and won't cost. Why are you so set on Embarcadero tools? It seems like the wrong approach for VST3. If your subscription lapses then it's over. You can't upgrade. You need to buy a new license if you want to get a new version. Very bad model in my view.
  18. David Heffernan

    PowerBuilder Code Covert to Delphi

    The Windows API functions have the same name no matter which language you call them from. This just hunts out a window by name and class, finds its first child window, and makes this window be its child. However, your real problem is that, with probability > 0.99, cross-process parenting isn't a viable solution for any problem. You say that your knowledge of winapi is not good. Well, it's going to be impossible to write this program without good knowledge of winapi. If at any point in time, you find yourself not knowing something, you must study until you acquire that knowledge. Or hire somebody that already has the knowledge.
  19. Thus is exactly what I do and it's really not difficult. The only challenge is header file translation. Having said that, this is true for libraries with a C style interface. If it's C++ classes then you need to wrap them which is more laborious.
  20. David Heffernan

    Change of coding style/structure..

    This blows my mind. The try/finally is to protect the resource. So you must enter the try immediately after the resource has been acquired. I suggest that you read Dalija's book on memory management.
  21. David Heffernan

    Change of coding style/structure..

    And then you need to call a few more methods and then you risk with hell. Or you need to pass the form reference to another method and you don't have it any more. So you change back to local variable pattern. Now have you multiple different patterns for the same task. Which is fine if the different patterns bring significant benefit. But they don't. So use a single unified pattern.
  22. David Heffernan

    Change of coding style/structure..

    If using a local variable with the basic try finally, Create, ShowModal, Free pattern is complicated and requires simplification, then I think you may have deeper problems.
×