Class unit
The unit Un_Class;
Interface
USES System. Classes, Un_Interface;
Type
TTest=class (TInterfacedObject ITest)
Public
The function getdate (value: string) : string; The phrase ";
The function getvalue: string; The phrase ";
end;
Implementation
{TTest}
Function TTest. Getdate (value: string) : string;
The begin
Result: the value=
end;
The function TTest. Getvalue: string;
The begin
Result:='FFFFF';
end;
End.
Interface unit
The unit Un_Interface;
Interface
USES the System. The Classes;
Type
ITest=interface (IInterface)
[' {4 d2 f3260eb - 99-47 be e4-89-7 d8862cb05f7} ']
The function getdate (value: string) : string;
The function getvalue: string;
end;
Implementation
End.
Finally, in the main window called
USES Un_Interface;
Procedure TForm1. Button1Click (Sender: TObject);
Var aa: ITest;
The begin
ShowMessage (aa) getvalue);
end;
Execution will address mistakes, could you tell me how the whole?
CodePudding user response:
Your interface has no implementation class! So the execution will address mistakesCodePudding user response:
Var aa: ITest;Aa you must have something to assign a value to call
CodePudding user response:
This is the implementation class Un_Class unit, aa assignment?CodePudding user response:
Aa:=TTest. Create as ITest;CodePudding user response:
The modest failed to in-depth study,CodePudding user response:
Aa:=TTest. Create as ITest; Tried to add this sentence again call interface function normalThere is a problem to reference implementation class that how to realize the implementation class units function is how to implement is invisible to the others?
CodePudding user response:
You write a function in interface unit number.As getITest: itest
The begin
Result:=TTest. Create as ITest;
end;
CodePudding user response:
Interface must be implemented to use others, you can do an interface in internal factories such as call InterfaceFactory, then the other interfaces are registered to save up the factory, then can obtain interface by this factory, and also can not expose your implementation to others, the plant through the QueryInterface for this interface