The understanding of polymorphism helps to understand the polymorphic mechanisms of Tstream abstract classes.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.