Do I need to setLength a dynamic array on initialization?

后端 未结 5 1394
终归单人心
终归单人心 2020-12-10 20:03
type Tmyclass = class(TObject)
  somearray: array of TSometype
  FBool: Boolean;
  Fint: Integer;
  Fstr: string;
  constructor Create;
  destructor Destroy; overrid         


        
5条回答
  •  情话喂你
    2020-12-10 20:21

    As the other answerers have said, you do not need to initialize class member fields.

    You also asked about local variables. Yes, you do need to initialize those. All of them, except variables of one of the managed types:

    • AnsiString
    • UnicodeString
    • WideString
    • an interface type
    • dynamic array type
    • Variant

    List taken from Barry Kelly's answer that Sertac pointed out in the comments: Which variables are initialized when in Delphi?

提交回复
热议问题