Eugine Savin
Members-
Content Count
19 -
Joined
-
Last visited
Community Reputation
4 NeutralTechnical Information
-
Delphi-Version
Delphi 11 Alexandria
-
Compile time issue with RTTI, generic interface and type casting...
Eugine Savin replied to Ali Dehban's topic in RTL and Delphi Object Pascal
You can do it without TValue if TypeInfo(T) = TypeInfo(Integer) then PInteger(@Result)^ := 10 else if TypeInfo(T) = TypeInfo(string) then PString(@Result)^ := 'Hello' -
Create a new instance of a generic class
Eugine Savin replied to A.M. Hoornweg's topic in RTL and Delphi Object Pascal
Ha, delphi 10.4 has a bug here. type iSomeInterface<T> = interface end; Type tSomeclass<T:iInterface>=CLass (tInterfacedObject, iSomeInterface<T>) Constructor Create(s: string); Function CreateNewInstance:iSomeInterface<T>; end; Function tSomeclass<T>.CreateNewInstance:iSomeInterface<T>; type TSelfClass = tSomeclass<T>; TSomeClassType = class of TSelfClass; // !!!!!!!!!!!! [dcc32 Error] Unit9.pas(36): E2021 Class type required begin result:=TSomeClassType(Self.Classtype).Create('s'); //Does not compile end; -
cCircleZero: TCircle = (C: (x: 0; y: 0); Radius: 0.0);
-
Current output is 'ne', I think, it's a bug. If I explicitly set type of variable B to Currency - output will be 'eq' as expected. I use Delphi 10.4 (also please check this code in Delphi 11) program Project3; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; function GetCurrency: Currency; begin Result := 8.52; end; var A: Currency; begin A := GetCurrency; //var B: Currency := GetCurrency(); // 1 var B := GetCurrency(); // 2 if A = B then WriteLn('eq') else WriteLn('ne'); ReadLn; end.
-
Is set a nullable type? (record constraint)
Eugine Savin replied to Eugine Savin's topic in RTL and Delphi Object Pascal
Oh, sorry, my fault, I believe that I have similar code but it does not have generic constraints. Perhaps I ran into this issue earlier, but forgot about it -
Is set a nullable type? (record constraint)
Eugine Savin replied to Eugine Savin's topic in RTL and Delphi Object Pascal
As least Delphi Tokio compiles this code successfully -
Is set a nullable type? (record constraint)
Eugine Savin posted a topic in RTL and Delphi Object Pascal
if I pass set type into MyGenericMethod<T: record> - I get compile type error [dcc32 Error] Project2.dpr(28): E2512 Type parameter 'T' must be a non-nullable value type Is it OK or compiler bug ?? program Project2; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; type TMyEnum = (en1); TMySet = set of TMyEnum; type TTestClass = class class procedure MyGenericMethod<T: record>; end; class procedure TTestClass.MyGenericMethod<T>; begin // end; begin try { TODO -oUser -cConsole Main : Insert code here } TTestClass.MyGenericMethod<TMySet>(); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. -
class function TNumbers.FromInteger<T>(AValue: Integer): T; type PSingle = ^Single; begin if TypeInfo(T) = TypeInfo(Single) then PSingle(@Result)^ := AValue else if TypeInfo(T) = TypeInfo(Integer) then PInteger(@Result)^ := AValue else raise Exception.Create('Error Message'); end;
-
type TNumbers = class public class function One<T>: T; end; { TNumbers } const OneSingle: Single = 1; OneInteger: Integer = 1; class function TNumbers.One<T>: T; type PT = ^T; begin if TypeInfo(T) = TypeInfo(Single) then Result := PT(@OneSingle)^ else if TypeInfo(T) = TypeInfo(Integer) then Result := PT(@OneInteger)^ else raise Exception.Create('Error Message'); end; ... FPen.Width := TNumbers.One<T>;
-
MultiCast NotifyEvents / DatasetNotifyEvents
Eugine Savin replied to microtronx's topic in Algorithms, Data Structures and Class Design
https://bitbucket.org/sglienke/spring4d/src/ffee3360a2e8cb9ae5311621a745bb9ed809870f/Source/Base/Spring.pas#lines-956 ?- 4 replies
-
- delphi
- multicast events
-
(and 1 more)
Tagged with:
-
This shouldn't work. Make method Test virtual and override it in Test2
-
operator overloding Equal vs Multiply
Eugine Savin replied to Eugine Savin's topic in RTL and Delphi Object Pascal
In C++ there is not differences between functions and overloaded operators. struct MyArray { public: template <std::size_t N> bool operator==(int (&rhs)[N]) { std::cout << N << '\n'; return true; } }; int main() { // your code goes here int arr1 [1] = {0}; int arr2 [2] = {0, 0}; MyArray myArr; if (myArr == arr1 && myArr == arr2) {} return 0; } Can you explain why you allow operators with dyn arrays, and do not allow ones with open arrays ? -
operator overloding Equal vs Multiply
Eugine Savin replied to Eugine Savin's topic in RTL and Delphi Object Pascal
TMyArray = record .. end; const Arr1: array[0..1] of Integer = (..) const Arr2: array[0..2] of Integer = (..) var MyArray: TMyArray .. I wanna have ability to compare if (MyArray == Arr1) or (MyArray = Arr2).. How can I get it without open arrays as operator parameters ? -
operator overloding Equal vs Multiply
Eugine Savin replied to Eugine Savin's topic in RTL and Delphi Object Pascal
What's problems with open arrays ? Anyway if I replace "array of Integer" by "TArray<Double>" r * [10.0] - compiled, but r = [10.0] is not ( E2001 Ordinal type required) // qc link https://quality.embarcadero.com/browse/RSP-23498 -
operator overloding Equal vs Multiply
Eugine Savin replied to Eugine Savin's topic in RTL and Delphi Object Pascal
And main question, why r := r * [10] // here [10] is array and b := r = [10] // here [10] is set what's difference ??