[fpc-pascal] get class of procedure variable

2020-05-29 Thread Ryan Joseph via fpc-pascal
In the example below "callback" is assigned to a method of "obj", but is it 
possible to get the class back from the variable? In the pseudo code I would 
expect .GetClass to return "obj". I think "of object" must be a record which 
keep both the class and method pointer but I don't know how to access it.

  
  type TCallback = procedure of object;
  var 
callback: TCallback;
obj: TObject;
  begin
callback := obj.SomeMethod;
  
// get the class which callback is assigned to
if callback.GetClass = XXX then
  ;

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] get class of procedure variable

2020-05-29 Thread Michael Van Canneyt



On Fri, 29 May 2020, Ryan Joseph via fpc-pascal wrote:


In the example below "callback" is assigned to a method of "obj", but is it possible to get the 
class back from the variable? In the pseudo code I would expect .GetClass to return "obj". I think "of 
object" must be a record which keep both the class and method pointer but I don't know how to access it.


 type TCallback = procedure of object;
 var
   callback: TCallback;
   obj: TObject;
 begin
   callback := obj.SomeMethod;

   // get the class which callback is assigned to
   if callback.GetClass = XXX then


I think what you're looking for is:

if TMethod(CallBack).Data=XXX then

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] get class of procedure variable

2020-05-29 Thread Michael Van Canneyt



On Fri, 29 May 2020, Michael Van Canneyt wrote:




On Fri, 29 May 2020, Ryan Joseph via fpc-pascal wrote:

In the example below "callback" is assigned to a method of "obj", but is it 
possible to get the class back from the variable? In the pseudo code I would 
expect .GetClass to return "obj". I think "of object" must be a record which 
keep both the class and method pointer but I don't know how to access it.



 type TCallback = procedure of object;
 var
   callback: TCallback;
   obj: TObject;
 begin
   callback := obj.SomeMethod;

   // get the class which callback is assigned to
   if callback.GetClass = XXX then


I think what you're looking for is:

if TMethod(CallBack).Data=XXX then


Small addendum, if you're looking for the class (i.e. the type) then that
would be:

  if TObject(TMethod(CallBack).Data).Classtype=XXX then

TMethod is part of the system unit.
  https://www.freepascal.org/docs-html/rtl/system/tmethod.html

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] get class of procedure variable

2020-05-29 Thread Ryan Joseph via fpc-pascal


> On May 29, 2020, at 2:15 PM, Michael Van Canneyt  
> wrote:
> 
> I think what you're looking for is:
> 
> if TMethod(CallBack).Data=XXX then

TMethod is exactly what I was looking for. Thank you Michael.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Implementing a simple tcp/ip connection

2020-05-29 Thread Giuliano Colla

Il 28/05/2020 18:00, Graeme Geldenhuys ha scritto:


Though in general, I would
just use Indy.

+1
The main reason is that I have a relevant amount of Delphi/Kylix code 
using Delphi's Sockets unit. That way porting that code to Lazarus 
becomes trivial.
Secondly my applications typically involve point-to-point connections in 
a production environment. Upstream machine must communicate with 
downstream machine, end of line machine must send production data to a 
dedicated server, and so on. I need to transparently handle failures 
such as a server side being temporary down. All of that in the hands of 
unskilled operators.

Lighter and simpler code, makes it easier both to develop and to debug.

Giuliano

--
Do not do to others as you would have them do to you.They might have different 
tastes.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal