Can I define a type inside a class in Object Pascal?

Here is an example (which does not work):

type menu = class private menu_element = RECORD id: PtrUInt; desc: string; end; public procedure foo(); end; 
+5
source share
2 answers

Yes, you can. But since you want to declare a type, you must enter a valid expression

 type menu = class private type menu_element = RECORD id: PtrUInt; desc: string; end; end; 
+5
source

Free Pascal accepts this if you change "=" to ":". Fields are declared using ":", types with "="

 {$mode Delphi} type menu = class private menu_element : RECORD id: PtrUInt; desc: string; end; public procedure foo(); end; procedure menu.foo; begin end; begin end. 

Turbo Pascal and Delphi (and FPC before 2.2) prohibit this. Free Pascal has restored this old behavior (Classic Pascal) due to dialects of Apple.

+3
source

Source: https://habr.com/ru/post/1207936/


All Articles