| Variant Records: The equivalent to the C-union structure |
| Is there a way to create a C 'union'-like structure in Delphi? That is, a structure that uses the same memory area? The Delphi (Pascal/ObjectPascal) equivalent to a C-union structure is called a Variant Record (not to be confused with the Variant "type" available in Delphi 2.0+). As with a C-union, the Pascal variant record allows several structure types to be combined into one, and all will occupy the same memory space. Look up the syntax declaration under "Records" in the help file. But here's an example: type TPerson = record The record above is actually a single expression of two records that could describe a person: type and type And as in a union, the combination of the two types of records makes for much more efficient programming, because a person could be expressed in a variety of ways. Everything I explained above is pretty hypothetical stuff. In Delphi, the TRect structure that describes a rectangle is actually a variant record: type TRect = record where the coordinates of the rectangle can be expressed using either four integer values or two TPoints. I realize this is pretty quick and dirty, so I suggest you refer to the help file for a more in-depth explanation, or go to your nearest book store or library and look at any Pascal book (not Delphi -- most won't explain this fairly esoteric structure). However, if you're familiar with the C-union, this stuff should be an absolute breeze. Copyright 1997 Brendan V. Delumpa All Rights Reserved |
Variant Records: The equivalent to the C-union structure
最新推荐文章于 2024-10-24 20:25:39 发布
博客可能围绕Delphi和Pascal展开,涉及structure、string、integer等类型相关内容,属于信息技术领域中编程语言相关知识。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Llama Factory
模型微调
LLama-Factory
LLaMA Factory 是一个简单易用且高效的大型语言模型(Large Language Model)训练与微调平台。通过 LLaMA Factory,可以在无需编写任何代码的前提下,在本地完成上百种预训练模型的微调

1376

被折叠的 条评论
为什么被折叠?



