[fpc-pascal] How to set a CORBA interface property (tkInterfaceRaw) through RTTI

Luiz Americo Pereira Camara luizmed at oi.com.br
Tue Jul 20 22:43:31 CEST 2010


Hi,

I've managed to set a COM interface property (tkInterface) through RTTI =

using SetInterfaceProp.

But i could not find a way to set a CORBA interface property =

(tkInterfaceRaw) since SetInterfaceProp expects IUnknown.

In the attached example, when i try to use SetInterfaceProp i get the =

message "Incompatible type for arg no. 3: Got "IMyIntf", expected =

"IUnknown"".

Is there a way to set a CORBA interface property through RTTI?

Luiz

-------------- next part --------------
program bugIntfRTTI;

{$mode objfpc}{$H+}

{$Define USE_CORBA}

uses
  Classes, typinfo;

type

  {$ifdef USE_CORBA}
  {$INTERFACES CORBA}
  {$endif}

  IMyIntf =3D interface
    procedure DoIt;
  end;


  {$ifdef USE_CORBA}
  TMyIntfImpl =3D class(TObject, IMyIntf)
    procedure DoIt;
  end;
  {$else}
  TMyIntfImpl =3D class(TInterfacedObject, IMyIntf)
    procedure DoIt;
  end;
  {$endif}


  TMyObj =3D class(TComponent)
  private
    FIntf: IMyIntf;
    procedure SetIntf(const Value: IMyIntf);
  published
    property Intf: IMyIntf read FIntf write SetIntf;
  end;

procedure TMyObj.SetIntf(const Value: IMyIntf);
begin
  FIntf :=3D Value;
  WriteLn('SetIntf: ' + hexStr(FIntf));
end;

procedure TMyIntfImpl.DoIt;
begin
  WriteLn('DoIt - ', {$ifdef USE_CORBA}'CORBA'{$else}'COM'{$endif});
end;

var
  Obj: TMyObj;
  Impl: IMyIntf;
  PropInfo: PPropInfo;

begin
  Impl :=3D TMyIntfImpl.Create;
  Obj :=3D TMyObj.Create(nil);

  PropInfo :=3D GetPropInfo(PTypeInfo(Obj.ClassInfo), 'Intf');

  if PropInfo <> nil then
  begin
    WriteLn('PropInfo Found: ' + GetEnumName(TypeInfo(TTypeKind), Integer(P=
ropInfo^.PropType^.Kind)));
    SetInterfaceProp(Obj, PropInfo, Impl);
    Obj.Intf.DoIt;
  end
  else
    WriteLn('PropInfo NOT Found');

  Obj.Destroy;
end.



More information about the fpc-pascal mailing list