Delphi-error e2154 type '% s' needs finalization-not allowed in variant rec

Source: Internet
Author: User

Technical Exchange, DH explanation.

This error mainly occurs in the variant part of the struct. When the variant part contains an indefinite data, the compiler reports an error.
Let's take a look:

Type data = record case kind: Char of 'A': (STR: string); end;

We know that the variant structure determines the size of this struct during compilation, but it cannot be determined.
So how can we modify it?
1. Do not place the variable part when there is no long data. For example:

Type data = record STR: string; end;

2Change to pointer
For example, if you change it to pstring, it is not recommended. There is no destroy method for the struct. Sometimes, if we manually allocate space, it cannot be released.

In addition to string, array of type also causes this error.

Okay, I'm DH. Thank you.

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.