Jan 272018

The ToolsAPI interface IOTAComponent declares two methods for getting property values:

  IOTAComponent = interface(IUnknown)
  // [...]
    { Given the index or name, returns the property value. The untyped var
      must be large enough to hold the returned value.  If the property is
      a descendant of TPersistent, the return value is a IOTAComponent. For
      properties of any other object type, the return value is nil. }
    function GetPropValue(Index: Integer; var Value): Boolean;
    function GetPropValueByName(const Name: string; var Value): Boolean;

The comment says “The untyped var must be large enough to hold the returned value.” which pretty much lets us guess, how large it must be for an enum (or even a Boolean). Let’s say, we want to read the Enabled property of a component, do we simply pass a Boolean? Or for the Anchors property, do we pass a TAnchors variable (which is a set of TAnchorKind)?

David Hoyle’s The Delphi Open Tools API Book only mentions what to pass for strings. I had to find out the hard way: For Enums, Booleans and Sets, the methods always expect 4 bytes. So for enums and sets, better pass an integer, for Booleans, pass a LongBool.

  BoolValue: LongBool;
  IntValue: integer;
  AlignValue: TAlign;
  if _Component.GetPropValueByName('Align', IntValue) then begin
    AlignValue := TAlign(IntValue);
    _Component.GetPropValueByName('AlignWithMargins', BoolValue);