Why most Delphi examples use FillChar() to initialize records?

前端 未结 8 2092
离开以前
离开以前 2020-12-13 06:32

I just wondered, why most Delphi examples use FillChar() to initialize records.

type
  TFoo = record
    i: Integer;
    s: string; // not safe in record, b         


        
8条回答
  •  醉酒成梦
    2020-12-13 07:18

    Traditionally, a character is a single byte (no longer true for Delphi 2009), so using fillchar with a #0 would initalize the memory allocated so that it only contained nulls, or byte 0, or bin 00000000.

    You should instead use the ZeroMemory function for compatibility, which has the same calling parameters as the old fillchar.

提交回复
热议问题