Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Delphi
  4. [SOLVED] Assigning Properties and Events At Runtime

[SOLVED] Assigning Properties and Events At Runtime

Scheduled Pinned Locked Moved Delphi
com
2 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AmbiguousName
    wrote on last edited by
    #1

    hello guys... I have a small component from which I got a wrapper (.tlb) by importing and installing the component. I dropped the component from toolbox to TMainFormDialog and got events. But I want to redirect these events to some other class NOT the TMainFormDialog. Now I am , well sort of, not moving forward. Well I am not sure but I think I should be able to do this using RTTI. I think I should make and assign new properties (THE events) to the old ones. This is the psuedo-code that I tried.

    TServer = class (TOleServer)

    private
    FOnEventEx : TNotifyEvent; // new one
    FOnEvent : TNotifyEvent; // old one

    published
    property OnEventEx : TNotifyEvent read FEventEx write FEventEx ; // new one
    property OnEvent: TNotifyEvent read FEvent write FEvent; // old one

    public
    procedure FireThisProc(); // This is the event I want to be fired ----------- based on new property 'OnEventEx'.
    end;

    Now I tried the GetMethodProc()and SetMethodProc() in the Create function of .tlb wrapper like this but could not succeed.

    class function CoServer : IServer
    begin
    MethodProp := GetMethodProp(TObject(TServer), 'OnEventEx');
    SetMethodProp(TObject(TServer) , 'OnEvent', MethodProp);

    Result := CreateComObject(CLASS_Server) as IServer;
    end;

    So what (and how) should I do it exactly so that I might be able to redirect my events to some other class, NOT the TMainFormDialog. Thanks for any pointers or suggestions.

    This world is going to explode due to international politics, SOON.

    S 1 Reply Last reply
    0
    • A AmbiguousName

      hello guys... I have a small component from which I got a wrapper (.tlb) by importing and installing the component. I dropped the component from toolbox to TMainFormDialog and got events. But I want to redirect these events to some other class NOT the TMainFormDialog. Now I am , well sort of, not moving forward. Well I am not sure but I think I should be able to do this using RTTI. I think I should make and assign new properties (THE events) to the old ones. This is the psuedo-code that I tried.

      TServer = class (TOleServer)

      private
      FOnEventEx : TNotifyEvent; // new one
      FOnEvent : TNotifyEvent; // old one

      published
      property OnEventEx : TNotifyEvent read FEventEx write FEventEx ; // new one
      property OnEvent: TNotifyEvent read FEvent write FEvent; // old one

      public
      procedure FireThisProc(); // This is the event I want to be fired ----------- based on new property 'OnEventEx'.
      end;

      Now I tried the GetMethodProc()and SetMethodProc() in the Create function of .tlb wrapper like this but could not succeed.

      class function CoServer : IServer
      begin
      MethodProp := GetMethodProp(TObject(TServer), 'OnEventEx');
      SetMethodProp(TObject(TServer) , 'OnEvent', MethodProp);

      Result := CreateComObject(CLASS_Server) as IServer;
      end;

      So what (and how) should I do it exactly so that I might be able to redirect my events to some other class, NOT the TMainFormDialog. Thanks for any pointers or suggestions.

      This world is going to explode due to international politics, SOON.

      S Offline
      S Offline
      smags13
      wrote on last edited by
      #2

      Is RTTI the only way to do? Check if TMethod.Code contains empty info. and you're redirecting properties on TServer class, not a TServer object.

      if MethodProp.Code <> Nil then
      begin
      //Sometimes OutputDebugString is neat for debugging components/pkg
      OutputDebugString('Property Found.');
      SetMethodProp(TObject(TServer) , 'OnEvent', MethodProp);
      end
      else
      begin
      OutputDebugString('Property Not Found.');
      end;

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups