Reputation: 101
I have a really strange bug, I tried to restart my IDE but it didn't fixed it.
I've created a interface that looks like this:
myInterface = interface
['{delphi guid key here}'] (CTRL+ALT+G)
function getDataPCE : IDataPCE;
property dataPCE : IDataPCE read getDataPCE;
(some other properties that works)
end;
Then i created my object that inherits from this interface of course
myObject = class(TInterfacedObject, myInterface)
private
...
function getDataPCE : IDataPCE;
...
public
...
property dataPCE : IDataPCE read getDataPCE;
...
end;
the "..." means there some other properties and functions but not related to this.
And I'm getting this error: "Incompatible types"
How can I solve this?
EDIT
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;
Upvotes: 2
Views: 3454
Reputation: 613461
For the sake of helping you understand how to ask a question, here is the MCVE that you should have submitted.
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.
This results in this error:
[dcc32 Error] E2008 Incompatible types
The reason is that a property getter for a property of type IRioPiece
must be a function that accepts no parameters and has return type of IRioPiece
. But your getter function requires two arguments, and they need to come from somewhere. As written above, these arguments are not supplied when you access the property.
So you could fix the compilation error by changing the declaration of getDataPCE
to:
function getDataPCE: IRioPiece;
But that's almost certainly the wrong solution. Presumably you declared those parameters to getDataPCE
because you need to supply them. In which case you cannot remove them. Which means that you cannot declare a simple property dataPCE
that is backed by getDataPCE
. My guess is that you simply need to remove the dataPCE
property.
Of course, you could declare an array property like this:
property dataPCE[numRegister: String; numPCEFormated: String]: IRioPiece
read getDataPCE;
Which would mean you access the property like this:
dataPCE := resvervation.dataPCE[numRegister, numPCEFormatted];
But to me that is stretching the use of a property too far. I think it is better to access this using a function.
Conclusion
Remove the dataPCE
property and have consumers of the interface call getDataPCE
instead.
Upvotes: 8