Conditional behaviour based on concrete type for generic class

后端 未结 4 1786
北恋
北恋 2020-12-06 05:06

Since my question from yesterday was perhaps not completely clear and I did not get the answer I wanted, I will try to formulate it in a more general way:

Is there a

4条回答
  •  时光取名叫无心
    2020-12-06 05:46

    If someone is interested how I did implement my "worst-case size with special treatment for strings"

    class function RTTIUtils.GetDeepSize  (Variable : T) : Integer;
    var
      StringLength          : Integer;
      Ptr                   : PInteger;
    begin
    if (TypeInfo (T) = TypeInfo (String)) then
      begin
      Ptr := @Variable;
      Ptr := PInteger (Ptr^);
      Dec (Ptr);
      StringLength := Ptr^;
      Result := StringLength * SizeOf (Char) + 12;
      end
    else
      Result := 0;
    end;
    

    For me, this does the job at hand. Thanks to all contributors!

提交回复
热议问题