2015-04-14 66 views
1

我有一個非常奇怪的錯誤,我試圖重新啓動我的IDE,但它沒有修復它。德爾福不兼容的類型

我已經創建了一個看起來像這樣的接口:

myInterface = interface 
['{delphi guid key here}'] (CTRL+ALT+G) 
function getDataPCE : IDataPCE; 
property dataPCE : IDataPCE read getDataPCE; 
(some other properties that works) 
end; 

然後,我創建我的對象,當然從這個接口繼承

myObject = class(TInterfacedObject, myInterface) 
private 
    ... 
    function getDataPCE : IDataPCE; 
    ... 
public 
    ... 
    property dataPCE : IDataPCE read getDataPCE; 
    ... 
end; 

的「...」表示有一些其他屬性和功能但與此無關。

而且我得到這個錯誤:「不兼容類型」

我該如何解決這個問題?

編輯

IInfoNotisReservation = interface 
     ['{AE5CEC31-B2CE-4A3D-9CFE-6393646E4A04}'] 

     function getNumberPCE : String; 
     function getDataPCE(numRegister : String; numPCEFormated : String): IRioPiece; 
     procedure setNumberPCE(NumberPCE: String); 
     function getRegName : String; 
     procedure setRegName(RegName: String); 
     function getRegKey : String; 
     procedure setRegKey(RegKey: String); 

     property NumberPCE : String read getNumberPCE write setNumberPCE; 
     property RegName : String read getRegName write setRegName; 
     property RegKey : String read getRegKey write setRegKey; 
     property DataPCE : IRioPiece read getDataPCE; 
    end; 

type 
    TInfoNotisReservation = class(TInterfacedObject, IInfoNotisReservation) 

    private 
    DataBase : IDataBase; 
    SuperRio : ISuperRio; 
    RioN  : IRio; 
    fPCENum : String; 

    function getDataPCE(numRegister : String; numPCEFormated : String): IRioPiece; 
    function getNumberPCE: string; 
    function getRegKey: string; 
    function getRegName: string; 
    procedure setNumberPCE(NumberPCE: string); 
    procedure setRegKey(RegKey: string); 
    procedure setRegName(RegName: string); 
    procedure setRioN(Registre: string); 
    public 
    Constructor Create; 
    property DataPCE : IRioPiece read getDataPCE; 
    property NumberPCE : String read getNumberPCE write setNumberPCE; 
    property RegName : String read getRegName write setRegName; 
    property RegKey : String read getRegKey write setRegKey; 

end; 

function TInfoNotisReservation.getDataPCE(numRegister, 
    numPCEFormated: String): IRioPiece; 
begin 
    setRioN(numRegister); 
    Result := RioN.GetPieceByID(RioN.PieceNumberToID(NumPCEFormated).Item[0].ID, FLAG_IGNORE_SECURITY); 
end; 
+0

問題中的代碼編譯得很好。請提供一個演示您的問題的MCVE。就目前而言,這個問題將作爲主題而被關閉,因爲問題中的代碼沒有顯示您報告的問題。 –

+0

你想要什麼?我不明白爲什麼它說不兼容類型。在這裏你有我用於這個實施的一切... –

+1

請提供一個演示問題的MCVE。問題中的代碼不會產生您報告的錯誤。哦,還有一件事。始終總是報告錯誤消息,並始終指出它們出現的位置。 –

回答

7

爲了幫助您瞭解如何問問題的緣故,這裏是你應該提交的MCVE。

type 
    IRioPiece = interface 
    end; 

    IInfoNotisReservation = interface 
    ['{AE5CEC31-B2CE-4A3D-9CFE-6393646E4A04}'] 
    function getDataPCE(numRegister: String; numPCEFormated: String): IRioPiece; 
    property dataPCE: IRioPiece read getDataPCE; // ERROR HERE 
    end; 

begin 
end. 

這導致了這個錯誤:

[dcc32 Error] E2008 Incompatible types

的原因是,一個屬性的getter爲IRioPiece類型的屬性必須是一個不接受任何參數和返回具有的IRioPiece類型的函數。但是你的getter函數需要兩個參數,他們需要來自某個地方。如上所述,訪問屬性時不提供這些參數。

所以,你可以通過改變getDataPCE的聲明修復編譯錯誤:

function getDataPCE: IRioPiece; 

但是,這幾乎可以肯定錯誤的解決方案。據推測您將這些參數聲明爲getDataPCE,因爲您需要提供這些參數。在這種情況下,您無法刪除它們。這意味着您無法聲明由getDataPCE支持的簡單屬性dataPCE。我的猜測是,你只需要刪除dataPCE屬性。

當然,你可以聲明array property這樣的:

property dataPCE[numRegister: String; numPCEFormated: String]: IRioPiece 
    read getDataPCE; 

這將意味着你訪問屬性是這樣的:

dataPCE := resvervation.dataPCE[numRegister, numPCEFormatted]; 

但對我來說這是拉伸使用屬性太遠。我認爲使用函數訪問它會更好。

結論

取出dataPCE財產,並有接口調用getDataPCE,而不是消費者。

+0

但我需要那些參數 –

+1

確實如此。這意味着一個財產並不合適。 –

+0

是的好,所以它的工作原理,但有點奇怪它不適用於一個屬性。我刪除它,並將該功能在公開聲明,所以它會像那樣工作,但是..:/謝謝你的幫助 –