Forked from superswanman/OpOverloadWithGenerics.pas
Created
November 29, 2016 20:08
-
-
Save jpluimers/f9db5497259e3f0ea6bcec9bf654603f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
TObjectHelper = class helper for TObject | |
public | |
class function &&op_LogicalOr<T: class>(A, B: T): T; static; | |
end; | |
class function TObjectHelper.&&op_LogicalOr<T>(A, B: T): T; | |
begin | |
if A <> nil then | |
Result := A | |
else | |
Result := B; | |
end; | |
procedure Test; | |
var | |
sl1, sl2, sl3: TStringList; | |
begin | |
sl1 := nil; | |
sl2 := TStringList.Create; | |
sl3 := sl1 or sl2; // -> sl3 = sl2 | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment