[fpc-pascal] TypeInfo question

Ryan Joseph ryan at thealchemistguild.com
Fri Mar 24 03:51:20 CET 2017

I think I already learned this and I forget when I had the idea about TypeInfo. :) 

This is basically the pattern I’m attempting. I have a generic class and I thought I could avoid specializing and making a subclass so that I could call a method if the type of the generic was a class. So what happens as you now is that I can’t cast “value” to TObject because if the generic was specialized as an integer for example, the type cast would be illegal and I get stuck at compile time (Illegal type conversion: "LongInt" to "TObject”).

Is there anyway I could push the type checking to runtime? I wanted to using writeln also to perform some printing for debugging but I get stuck at compile time again trying to mix, integers, strings, records, classes etc… in the generic. I would use an interface but there are compiler types and records involved so that’s not an option.

	TLongIntMatrix = specialize TMatrix<LongInt>;
	TObjectMatrix = specialize TMatrix<TObject>;

function TMatrix.RetainValue (value: T): T;
	if typeKind = tkClass then
	result := value;

	Ryan Joseph

More information about the fpc-pascal mailing list