Why can't Delphi variants hold objects?

前端 未结 3 2220
时光说笑
时光说笑 2021-02-13 09:14

Why can\'t Delphi variants hold objects? More importantly, what\'s the reason behind this limitation?

3条回答
  •  渐次进展
    2021-02-13 09:40

    I had used Variants to hold objects in the past using the Variant internals, the code is something like this:

    var
      MyObject: TMyObject;
      Value: Variant;
    begin
      MyObject:= TMyObject.Create;
      TVarData(Value).VType:= VarByRef or VarUnknown;
      TVarData(Value).VPointer:= MyObject;
    

提交回复
热议问题