What is the name of this method?

In the encoding in the Delphi book, an example of an interface restriction is given:

1    type
2      IStoppable  =  interface
3        procedure Stop;
4      end;
5
6      TWidget<T: IStoppable>  =  class
7        FProcess: T;
8        procedure StopProcess;
9      end;
10
11   { TWidget<T> }
12
13   procedure  TWidget<T>.StopProcess;
14   begin
15     FProcess.Stop;
16   end;

I don’t understand on line 15 what he calls the Stop method? isn't FProcess a shared variable? So how can it call a method from a variable?

Also, how can he call the Stop method directly from the interface? Shouldn't he call an implemented method?

+4
source share
2 answers

FProcesshas a type Twhere it is Tlimited to an interface that is IStoppableeither one derived from IStoppable. Calling the method you are referencing calls the method Stop IStoppable.

Imagine being FProcessdeclared as a type IStoppable.

FProcess: IStoppable;

If that were the case, I think you will understand the code.

, , . . , .

, . , . , , , , . modus operandi .

+9

FProcess T, IStoppable, : T IStoppable ( ) , IStoppable

. , : , .

, -. .

+5

Source: https://habr.com/ru/post/1654338/


All Articles