Talk:Overloads and Type Compatibility in Generics
Contents
Borked angle brackets
The code samples in this topic are very hard to read, as the <angle brackets> are represented by their HTML codes.
Same thing has happened in the Constraints in Generics and Class Variable in Generics topics. I guess this is a further manifestation of the curse of the <source lang> tag, which I suppose treacherously does not expand HTML characters, unlike everything else in the whole Wikitext world.
Willw 02:37, 17 October 2011 (PDT)
Response
Ah, yes, those <> characters are definitely borked!
I have corrected the code snippets on the cited pages so that they use the literal characters rather than the HTML equivalents.
Many thanks for your comment --
Kris Houser Lead Writer, RAD Studio
RAD-10148
Compatibility with numeric types.
I have a dating Histogram component, having 10 sub-classes for different datatypes (single, double, signed and unsigned 8-, 16-, 32- and 64-bits integers). Thinking it is way too much of copy-paste i wanted to generalize them.
Class-level generalization makes too much code duplication and makes the class later unusable as member inside TWinControl derivative. So i am left with method-wide generalization.
function TDSpHisto.AddData<T>(var data: T; const num: integer;
const Quantity: cardinal): cardinal;
var i: integer;
bp: ^T;
min, max: T;
scale: TDSpFloat64;
begin
bp := @data;
min := Round(FMin);
max := Round(FMax);
scale := FBins / (max - min + 1);
...
This suddenly raises an error: [DCC Error] DSpHistogram.pas(189): E2010 Incompatible types: 'T' and 'Int64' But why ??? And how do regular Delphi types correspond to generics then ?
If there are restrictions in such usage - the documentation is to tell them and show workarounds. Or is documentation right omitting them and bug in compiler?
Response
Thank you for your input -
Here is the response from the Delphi compiler team
The error message is correct. Round does not take an argument of a type parameter type - it is not generic. In fact, generics are not like C++ templates.
Also please see note added to this topic.
KrisHouser 10:39, 25 October 2011 (PDT)
RAD-10174