Re: [fpc-pascal] Dynamic messaging in Delphi

2012-07-26 Thread Graeme Geldenhuys
On 24 July 2012 15:13, Ryan Joseph  wrote:
> procedure InvokeDelegate (delegate: TObject);
> var
> intfDelegate: IMyInterface;
> begin
> ERROR > intfDelegate := IMyInterface(delegate);
> intfDelegate.DoThis(1);
> end;


You could also try the Supports() method. eg:

   if Supports(delegate, IMyInterface, intfDelegate) then
 intfDelegate.DoThis(1);

>
> {$mode delphi}
> {$interfaces corba}
>
> program Main;
> uses
> MyInterface;
>
> type
> TMyDelegate = class (TInterfacedObject, IMyDelegate)
> procedure DoThis (value: integer);
> end;


By the way, as far as I know TInterfacedObject is a COM Interface
class only. You are telling the compiler that you want to use CORBA
style interfaces, which don't support IUnknown, thus you shouldn't
(can't) use TInterfaceObject which implements IUnknown.

Change that class definition to something like the following if you
are using CORBA interfaces.

   TMyDelegate = class(TObject, MyDelegate)
  ...
   end;

And that should work correctly with CORBA style interfaces (which
don't have reference counting built-in).


-- 
Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://fpgui.sourceforge.net
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Dynamic messaging in Delphi

2012-07-26 Thread Ryan Joseph

On Jul 26, 2012, at 2:32 AM, Graeme Geldenhuys wrote:

> 
> You could also try the Supports() method. eg:
> 
>   if Supports(delegate, IMyInterface, intfDelegate) then
> intfDelegate.DoThis(1);

I'm getting an identifier not found error with the procedure "Supports". Where 
is this defined?

> 
> By the way, as far as I know TInterfacedObject is a COM Interface
> class only. You are telling the compiler that you want to use CORBA
> style interfaces, which don't support IUnknown, thus you shouldn't
> (can't) use TInterfaceObject which implements IUnknown.
> 
> Change that class definition to something like the following if you
> are using CORBA interfaces.
> 
>   TMyDelegate = class(TObject, MyDelegate)
>  ...
>   end;
> 
> And that should work correctly with CORBA style interfaces (which
> don't have reference counting built-in).

That was useless code, you're right, thanks.

Regards,
Ryan Joseph
thealchemistguild.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


RE : [fpc-pascal] Dynamic messaging in Delphi

2012-07-26 Thread Ludo Brands
http://www.freepascal.org/docs-html/rtl/sysutils/supports.html

> I'm getting an identifier not found error with the procedure 
> "Supports". Where is this defined?
> 
> 

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Dynamic messaging in Delphi

2012-07-26 Thread Ryan Joseph
Great, I got this working now. 

This is one small step better because the only string identifier used in code 
for the interface is in the declaration itself so if the name of the interface 
gets changed I'll get compiler warnings when I try to invoke it.

Thanks.

On Jul 26, 2012, at 8:41 AM, Ludo Brands wrote:

> http://www.freepascal.org/docs-html/rtl/sysutils/supports.html
> 
>> I'm getting an identifier not found error with the procedure 
>> "Supports". Where is this defined?

Regards,
Ryan Joseph
thealchemistguild.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC and IPv6, and BSD

2012-07-26 Thread ZAN DoYe

On 2012-07-23 21:51, Mark Morgan Lloyd wrote:

I'm trying to write a simple finger daemon, capable of both IP4 and IP6. At 
present it's using an unprivileged socket so as to avoid problems on unix 
platforms.

I appear to be having problems at the bind() call for IP6 (returns -1), which I 
suspect is down to my incomplete understanding of the new sockaddr_in6 
structure. Has anybody done this successfully?


If you called fpBind, then check fpGetErrno to see what happened. If you do 
called the bind function in libc. uses initc unit, and check the cerrno.


As a subsidiary question: noting that a client has to be aware of this:

  sockaddr_in6 = packed Record
{$ifdef SOCK_HAS_SINLEN}  // as per RFC 2553
  sin6_len: cuint8;
{$endif}
sin6_family   : sa_family_t;
..

so that it initialises the sin6_len field if present (some BSD variants?), does 
it see that conditional automatically if defined? Otherwise how best to do it?


You don't worry about the sin6_len field.
`Even if the length field is present, we need never set it and need never 
examine it, unless we are dealing with routing sockets. It is used within the 
kernel by the routines that deal with socket address structures from various 
protocol families.' --- UNP v1

And you don't even need to be aware of sockaddr_in6 or sockaddr_in
as in a net lib:
function tTcpIpServer.listen(address, service: ansiString; backlog: cint): 
boolean;
var
hint: tAddrinfo;
addrinfo: paddrinfo;
encounterError: boolean= true;
begin
result:= false;
fillByte(hint, sizeof(hint), 0);
hint.ai_socktype:= SOCK_STREAM;
if getaddrinfo(pchar(address), pchar(service), @hint, @addrinfo) = 0 
then begin
if addrinfo <> nil then begin
handle:= fpSocket(addrinfo^.ai_family, SOCK_STREAM, 0);
if fpBind(handle, addrinfo^.ai_addr, addrinfo^.ai_addrlen) = 0 
then
encounterError:= false; // how lucky we are :)
end;
end;
freeaddrinfo(addrinfo);

if not encounterError then
if fpListen(handle, backlog) = 0 then
result:= true;
end;

We can invoke aTcpIpServer.listen('::0', '12345', 16) or 
aTcpIpServer.listen('0', '12345', 16), listen for incoming ip6/ip4 connections. 
getaddrinfo is handy.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal