i few days a go someone asked me why this code gives a error. i tried to figure out but i couldnt, so i hope u guys help us.
first unit: where the classe is defined unit Unit1;
interface
type
TSomeGeneric<T> = class
private
function getSelf: TSomeGeneric<T>;
public
property This : TSomeGeneric<T> read getSelf;
end;
implementation
{ TSomeGeneric<T> }
function TSomeGeneric<T>.getSelf: TSomeGeneric<T>;
begin
Result := Self;
end;
end.
unit2 : its makes a referente to the classe defined in unit 1 unit Unit2;
interface
uses
Unit1;
type
TSomeGeneric<T> = class(Unit1.TSomeGeneric<T>);
implementation
end.
frmmain: it uses unit2 is some point unit ufrmMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,
Unit2;
type
TfrmMain = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure SomeProcedure(ASG : TSomeGeneric<Integer>);
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
{ TfrmMain }
procedure TfrmMain.FormCreate(Sender: TObject);
var ASG : TSomeGeneric<Integer>;
begin
ASG := TSomeGeneric<Integer>.Create();
with ASG do
try
//make use os the class ...
SomeProcedure(This); //error -> incompatible types
finally
Free();
end;
end;
procedure TfrmMain.SomeProcedure(ASG: TSomeGeneric<Integer>);
begin
//...
end;
end.
i have a suspicious that at this point TSomeGeneric = class(Unit1.TSomeGeneric) the TSomeGeneric is defined as another classe and not a reference, but i cant confirm that
SomeProcedure(ASG)
instead ofSomeProcedure(This)
? – Rob Kennedy