- Mastering Delphi Programming:A Complete Reference Guide
- Primo? Gabrijel?i?
- 425字
- 2021-06-24 12:33:35
A plethora of types
The Delphi language contains an immense number of built-in types. There's no chance to cover them one by one, so let us firstly establish some classification that will simplify the rest of the discussion.
The most basic of all built-in types are simple types. In this group belong integer types (Byte, ShortInt, Word, SmallInt, Integer, Cardinal, Int64, UInt64, NativeInt, NativeUInt, LongInt, and LongWord), character types (Char, AnsiChar, WideChar, UCS2Char, and UCS4Char), boolean types (Boolean, ByteBool, WordBool, LongBool), enumerated types (such as TScrollBarStyle = (ssRegular, ssFlat, ssHotTrack)), and real types (Real48, Single, Real, Double, Extended, Comp, and Currency).
Similar to them are pointer types, such as pointer, PByte, ^TObject etc. They are, after all, just memory addresses, so we can always treat a pointer as a NativeUInt and vice versa.
Following them are strings, a very interesting family hiding intriguing implementation details. It contains short strings (such a string[42]), ansi strings (AnsiString, RawByteString, UTF8String), and unicode strings (string, UnicodeString, and WideString).
The last group is structured types. This group, which will be of great interest in this chapter, is composed of sets (such as TAlignSet = set of TAlign), arrays (static arrays and dynamic arrays), records (traditional and advanced—records with methods), classes, and interfaces. Anonymous methods can also be treated as interfaces as they are implemented in the same way.
A different classification, which I'll also occasionally use, splits all types into two groups—unmanaged and managed. Managed types are types for which the compiler automatically generates life cycle management code and unmanaged types are all the rest.
When a type's life cycle is managed, the compiler automatically initializes variables and fields of that type. The compiler also inserts the code that automatically releases the memory associated with data of such type when it is no longer used anywhere in the program (goes out of scope are the words often used).
Managed types include strings, dynamic arrays, and interfaces. Records are managed only when they contain at least one field of these types. On platforms that support ARC (iOS, Android, and Linux), classes are also managed.
Different types (more specifically, different classes of types) are implemented differently by the Delphi compiler and as such, present a different challenge for a developer. In the rest of this section, I'll describe the internal implementation of the most interesting data types.
- 圖解西門子S7-200系列PLC入門
- 基于Proteus和Keil的C51程序設(shè)計(jì)項(xiàng)目教程(第2版):理論、仿真、實(shí)踐相融合
- Effective STL中文版:50條有效使用STL的經(jīng)驗(yàn)(雙色)
- 施耐德SoMachine控制器應(yīng)用及編程指南
- scikit-learn:Machine Learning Simplified
- 單片機(jī)系統(tǒng)設(shè)計(jì)與開發(fā)教程
- SiFive 經(jīng)典RISC-V FE310微控制器原理與實(shí)踐
- Python Machine Learning Blueprints
- FL Studio Cookbook
- 基于網(wǎng)絡(luò)化教學(xué)的項(xiàng)目化單片機(jī)應(yīng)用技術(shù)
- Intel FPGA權(quán)威設(shè)計(jì)指南:基于Quartus Prime Pro 19集成開發(fā)環(huán)境
- 單片機(jī)原理及應(yīng)用
- Instant Website Touch Integration
- 計(jì)算機(jī)組裝、維護(hù)與維修項(xiàng)目教程
- 分布式存儲系統(tǒng):核心技術(shù)、系統(tǒng)實(shí)現(xiàn)與Go項(xiàng)目實(shí)戰(zhàn)