며칠 동안 누군가이 코드가 오류를 나타내는 이유를 묻습니다. 나는 알아 내지는 것을 시도했다 그러나 couldnt, 그래서 나는 사람들이 저희를 도울 것이라는 점을 희망한다.이 호환되지 않는 유형 오류가 무엇입니까?
첫 번째 단위 : classe가 정의 된 곳 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 유닛은 : (1)는이 유닛은 Unit2 에 정의 CLASSE에 referente한다;
interface
uses
Unit1;
type
TSomeGeneric<T> = class(Unit1.TSomeGeneric<T>);
implementation
end.
frmMain 수 : 그것은 어떤 점은 Unit2 부 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.
내가이 시점 TSomeGeneric = 클래스 (Unit1.TSomeGeneric)에서 TSomeGeneric 다른 CLASSE 아닌 참조로 정의되어 있는지 의심스러운,하지만 난
네, 확실히 다른 클래스입니다. 동일한 이름의 Unit1 클래스의 자손입니다. 그게 문제라고 의심되면 왜 그걸 확인하지 못하니? 대신 Unit2를 삭제하고 Unit1을 대신 사용하여 프로그램이 컴파일되고 작동하는지 확인하십시오. 'SomeProcedure (This) '대신'SomeProcedure (ASG)'를 호출하면 작동합니까? –
예 SomeProcedure (ASG)가 사용될 때 작동하지만 ASG.This 속성이 전달 될 때 작동하지 않습니다. 그게 내가 잃어버린 ASG 때문이야. 사실이게 또 다른 클래스 야? Unit.TSomeGeneric 및 Unit2.TSomeGeneric 이 프로 시저 매개 변수에 필요합니까? –
kabstergo