Sometimes it is not clear how the flow mechanism, because there is a stream of memory stream picture flow and so on, and their mutual transformation depends on the flow polymorphism ....
UnitUnit11;Interfaceuseswinapi.windows, Winapi.messages, System.sysutils, System.variants, system.classes, Vcl.graphics, Vcl.Controls, Vcl.forms, Vcl.dialogs, Vcl.stdctrls;typeTFORM11=class(tform) Btn1:tbutton; Btn2:tbutton; procedureBtn1click (Sender:tobject); procedureBtn2click (Sender:tobject); Private {Private Declarations} Public {Public Declarations} End; Tfulei=class Public functionFunc1 ():string;Virtual; End; Tzilei=class(Tfulei) Public functionFunc1 ():string;Override; End;varForm11:tform11;Implementation{$R *.DFM}functionTFULEI.FUNC1 ():string;beginExit ('func1');End;functionTZILEI.FUNC1 ():string;beginExit ('Func2');End;///<summary>///Note that the parameter here is the parent class, meaning that if it is possible to pass in the subclass, because the subclass has all the functions of the parent class, you can recursively///And if the subclass's coverage is a method of the parent class, then when the subclass is passed in, Delphi automatically calls the subclass's overridden method///</summary>procedureWokao (alei:tfulei);beginShowMessage (ALEI.FUNC1);End;procedureTform11.btn1click (sender:tobject);varLei:tfulei;beginLei:= Tfulei.Create; Wokao (LEI);//func1Lei. Free;End;procedureTform11.btn2click (sender:tobject);varLei:tzilei;beginLei:= Tzilei.Create; Wokao (LEI);//Func2Lei. Free;End;End.
Well, now I'm going to prove that if you can wokao the argument is a subclass, and then pass in the case of the parent class, because the parent class does not necessarily have all the functionality of the subclass.
It can be seen that my understanding is right, when the subclass is not allowed to pass in the parent class instance, will compile does not pass ...
The understanding of polymorphism helps to understand the polymorphic mechanisms of Tstream abstract classes.