Class/Static Constants in Delphi

前端 未结 9 733
粉色の甜心
粉色の甜心 2021-02-05 12:06

In Delphi, I want to be able to create an private object that\'s associated with a class, and access it from all instances of that class. In Java, I\'d use:

pub         


        
9条回答
  •  余生分开走
    2021-02-05 12:29

    Last year, Hallvard Vassbotn blogged about a Delphi-hack I had made for this, it became a two-part article:

    1. Hack#17: Virtual class variables, Part I
    2. Hack#17: Virtual class variables, Part II

    Yeah, it's a long read, but very rewarding.

    In summary, I've reused the (deprecated) VMT entry called vmtAutoTable as a variable. This slot in the VMT can be used to store any 4-byte value, but if you want to store, you could always allocate a record with all the fields you could wish for.

提交回复
热议问题