3

I'm playing around with the OmniThread lib, adding some functionality to the pipeline class.

I now want to add some attributes, but for this to work I need the RTTI to be generated.
It turns out that RTTI is disabled for all of Otl, by using the {$TYPEINFO OFF} directive.
Setting {$TYPEINFO ON} globally breaks the library, so that's not an option.

I'm trying to selectively enable RTTI for my own classes.

{$M+}
  {$RTTI EXPLICIT METHODS([vcPrivate,vcProtected,vcPublic, vcPublished]) PROPERTIES(([vcPrivate,vcProtected,vcPublic, vcPublished])) FIELDS(([vcPrivate,vcProtected,vcPublic, vcPublished]))}
  [Capabilities([SplitInput])]
  TOmniMultiPipelineSplitter = class(TOmniMultiPipelineStage, IOmniMultiSplitter)
  public
    /// <summary>
    /// Creates a splitter with 1 input and 2 outputs.
    /// Additional outputs can be added later if required.
    /// </summary>
    constructor Create; overload;
    constructor Create(const Input: IOmniBlockingCollection); overload;
    constructor Create(PrevStage: TGUID; PrevQueue: integer); overload;
    function AddOutputQueue: IOmniBlockingCollection;
  end;
  {$M-}

But no matter what I do the RTTI does not get genererated.

Here's the code that I'm using to get hold of the RTTI for my class:

  function FindAllFlavoursOf(basetype: TClass): TFlavours;
  var
    ctx: TRttiContext;
    lType: TRttiType;
  begin
    Result:= TList<TClass>.Create;
    ctx:= TRttiContext.Create;
    for lType in ctx.GetTypes do
      if (lType is TRttiInstanceType) and
        (TRttiInstanceType(lType).MetaclassType.InheritsFrom(basetype)) then begin
        Result.Add(TRttiInstanceType(lType).MetaclassType);
      end;
  end;

This code finds nothing for classes derived from TOmniMultiPipelineStage, however it does find something for classes derived from TInterfacedObject.
All classes with generic parameters seem to be included.

How do I get Delphi to put RTTI in my classes?

-- Yes, I did enable RTTI in the project settings: enter image description here

-- Yes the classes are used in my code. I run a pipeline that uses these classes when I press the Go button.

Johan
  • 74,508
  • 24
  • 191
  • 319
  • How does having `$TYPEINFO ON` break the library? – Mason Wheeler Jul 16 '14 at 18:34
  • If I change `OtlOptions.inc`:{$TYPEINFO OFF} to {$TYPEINFO ON}. It breaks all over the place. (At least in Delphi XE6). – Johan Jul 16 '14 at 18:38
  • 1
    You seem to be confusing old style type info $TYPEINFO with new style RTTI. – David Heffernan Jul 16 '14 at 19:19
  • Are the classes in question contained in the binary? Possibly the linker removed them because they are not used anywhere. You can check that by just printing out all classes returned by GetTypes. Also the settings you are showing have nothing to do with enhanced RTTI generation which is only controlled by the $RTTI directive. – Stefan Glienke Jul 16 '14 at 19:34
  • Yes, they are, because I'm running a pipeline containing these classes. – Johan Jul 16 '14 at 19:53

0 Answers0