Talk about classes and objects in Delphi: Iv. abstract classes and their examples

Source: Internet
Author: User

Iv. abstract classes and instances of it

Delphi has a class called abstract class, you can not naïve directly create an instance for it, such as

var    strlst:tstring;begin    strlst:= tstring.create;    Strlst.add (' I love China ');    Strlst.free;end;

This is wrong, because Tstring is an abstract class.

So how do you construct an instance for such an abstract class? The answer is to use its non-abstract subclasses. We know that Tstring has a non-abstract subclass of Tstringlist. So you can do this.

var    strlst:tstring;    Or can be declared through the abstract class    //or directly with Strlst:tstringlist;    But the former better some begin    strlst:= tstringlist.create;    However, creating a concrete object must use a non-abstract subclass of the abstract class         //And the created instance is in memory the structure of its subclass,         //Although the abstract class declaration is used in Var, but the specific create is its non-abstract subclass    Strlst.add (' I love China ');    Strlst.free;end;

  

  

Talk about classes and objects in Delphi: Iv. abstract classes and their examples

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.