Recent

Author Topic: Store procedure variables in a generic list  (Read 1684 times)

russdirks

  • New Member
  • *
  • Posts: 35
Store procedure variables in a generic list
« on: October 20, 2016, 07:41:33 pm »
I'm trying to store a list of (method) procedure variables using the generics fgl unit.  The following code gives me the compiler error "Wrong number of parameters specified for call to <Procedure Variable>" / "Illegal qualifier".  Is what I am trying to do possible?

Code: Pascal  [Select][+][-]
  1. uses fgl;
  2.  
  3. type
  4.  
  5.    TOnReceiveFn = Procedure (msg: string) of object;
  6.  
  7.    TRecvListeners = specialize TFPGObjectList<TOnReceiveFn>;
  8.  
  9.  

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Store procedure variables in a generic list
« Reply #1 on: October 20, 2016, 08:27:44 pm »
You could use TMethodList in the unit LCLProc, which is already fully functional and debugged.

russdirks

  • New Member
  • *
  • Posts: 35
Re: Store procedure variables in a generic list
« Reply #2 on: October 20, 2016, 09:51:21 pm »
Thanks.  That looks interesting.  Couldn't find too much documentation though.

How do I add an instance of my TOnReceiveFn to the list?  It's expecting a TMethod.

russdirks

  • New Member
  • *
  • Posts: 35
Re: Store procedure variables in a generic list
« Reply #3 on: October 20, 2016, 10:56:26 pm »
To answer my own question, TMethod can be directly cast to any procedure type, so I'm using something like this:

Code: Pascal  [Select][+][-]
  1. uses LCLProc;
  2.  
  3. type
  4.    TOnReceiveFn = Procedure (msg: string) of object;
  5.  
  6. var
  7.    m_recvListeners: TMethodList;
  8.  
  9. implementation
  10.  
  11. procedure CSocket.addListener(recvfn: TOnReceiveFn);
  12. begin
  13.    m_recvListeners.Add(TMethod(recvfn));
  14. end;
  15.  

 

TinyPortal © 2005-2018