I search for some trick to realize something like this:

I search for some trick to realize something like this:

ISome = interface
function GetValueVar() : Variant;
procedure SetValueVar(aValue : Variant);
function GetValue(aIndex : Integer) : Variant;
procedure SetValue(aIndex : Integer; aValue : Variant);

// two props with the same name
property Value[aIndex : Integer] : Variant read GetValue write SetValue;
property Value : Variant read GetValueVar write SetValueVar;
end;


var
x : ISome;
begin
x.Value := 0;
// or if I needed in other case
x.Value[0] := 'string';

Comments

  1. An ugly and brittle hack to work around the fact that records are value types and thus copied just to use a property in some ambiguous way.

    ReplyDelete
  2. Wow, that's a shockingly bad idea. Swim with the current, not against it.

    ReplyDelete
  3. Why not to use olevariant with single property ?
    OleVariant could handle any type of data and has info about type that is actually handling e.g

    TVarData(my property).vKind

    ReplyDelete

Post a Comment