IfThen issue with components
Original Reporter info from Mantis: silvioprog
-
Reporter name: silvioprog
Original Reporter info from Mantis: silvioprog
- Reporter name: silvioprog
Description:
Hello,
Take a look at this code below:
type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; TUtils = class sealed(TObject) public class function Iif&LtPos;T>(ACondition: Boolean; const ATrueValue, AFalseValue: T): T; static; end; var Form1: TForm1; implementation {$R *.dfm} class function TUtils.Iif&LtPos;T>(ACondition: Boolean; const ATrueValue, AFalseValue: T): T; begin if ACondition then Result := ATrueValue else Result := AFalseValue; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(TUtils.Iif&LtPos;TComponent>(True, Self, Button1).Name); ShowMessage(TUtils.Iif&LtPos;TControl>(False, Self, Button1).Name); end;
It works fine on Delphi, however, not I can use the new System.IfThen feature on FPC, but, how to use that with objects and components? When I try the code below:
type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.lfm} procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(IfThen(True, Self, Button1).Name); ShowMessage(IfThen(False, Self, Button1).Name); end;
I got:
Error: Incompatible types: got "TButton" expected "TForm1"
.
Additional information:
Related to http://bugs.freepascal.org/view.php?id=29546.
Mantis conversion info:
- Mantis ID: 29554