|
List Info
Thread: (
|
|
| ( |

|
2006-05-23 07:35:35 |
|
can someone explain me why i'm not able to pass to a function a
pointer of object using the ' '? What is amazing for me is that i could do
it
whitout ' ' (really i didn't try yet if it doesn't get exception at run
time).
The code is:
type TVProc = Procedure(a: integer) cdecl stdcall;
type TVMethod2 = Procedure(a: integer;b: integer) of object;
procedure MyProc2Test(a : integer;b : integer);
begin
end;
procedure TForm1.MyMethod2Test(a : integer;b : integer);
begin
end;
TEcovDLL.Create( MyProc2Test,MyMethod2Test);
where:
type TEcovDLL = class
private
...
public
constructor
Create(
_Proc2_JustStartedAtmel : TVProc2;
_Method2_JustStartedAtmel : TVMethod2);overload;
....
end;
and the call is
...
var ObjEcov : TEcovDLL;
...
ObjEcov := TEcovDLL.Create( MyProc2Test,MyMethod2Test); //compile
ObjEcov := TEcovDLL.Create( MyProc2Test, MyMethod2Test); //doesn't
compile
In all other way i had to use the function and method types, all works
writing as Rob wrote me,
using the ' ' to specify 'not call'.
2nd question:
If i write an other version of the constructor Create (class TEcovDLL),
declaring as 'overloaded'
both constructors, i'm not able anymore to call the first constructor with
two parameters 'nil', but
i need to specify the pointer to object. What can be the cause?
Best Regards,
Mauro Russo.
----- Original Message -----
From: "Rob Kennedy" <rkennedy cs.wisc.edu>
To: <delphi-en@yahoogroups.com>
Sent: Thursday, May 18, 2006 8:08 AM
Subject: Re: [delphi-en] Re: :(
> Mauro Russo wrote:
> > i'm using a Dll wrote in C++Builder.
> > I'm growing that Dll (i mean i have the source code of the Dll, so i can
> > manipulate it).
> >
> > I wanted to add in the call of a function of Dll a "pointer to method",
> >
> > (for example :
> >
> > typedef __stdcall void (__closure *TmyMethod)(int,int);
> >
> > #define NO_MAGLE extern "C"
>
> Declaring a function to use "C" linkage doesn't disable name mangling.
> It just uses different, less drastic name mangling.
>
> > #define DLL_EXPORT __declspec(dllexport)
> > #define DLL_PORT NO_MANGLE DLL_EXPORT
> >
> > DLL_PORT __stdcall void FuncDll(TmyMethod F){
> > ....
> > F(1,2);
> > ....
> > }
> >
> > )
> >
> > but i didn't want to trust that C++Builder and Delphi use the same way
to
> > manipulate TMethod (and similars),
>
> So all this hassle is because you don't trust Borland to make both
> products work together? Are you aware that components compiled in Delphi
> can be used in C++ Builder without recompiling? Since nearly every
> component has event properties, that's clear evidence that C++ Builder
> and Delphi use the same format for method pointers.
>
> Note that TMethod is not a method pointer. It's just a record. That
> record's structure happens to represent the internal structure of a
> method pointer, but Delphi also supports native types that actually
> *are* method pointers. They're the "of object" types. C++ Builder uses
> the "__closure" keyword for the same purpose. Forget about TMethod. Use
> the real method-pointer types.
>
> > so i semplified the type of pointer using
> > a:
> >
> > typedef __stdcall void (*TmyProcedureCallingMethod)(int,int,void *
PMethod);
>
> Void* is almost never the correct choice for a type. Figure out what
> it's *really* supposed to point at, and then use that type, not void.
>
> > DLL_PORT __stdcall void FuncDll(TmyProcedureCallingMethod P,void *
PMethod){
> > ....
> > P(1,2,PMethod);
> > ....
> > }
> >
> > and (in Delphi)
> >
> > <<
> >
> > type TMyMethod = procedure(a : integer;b : integer) of object;
> > type PTMyMethod = ^TMyMethod;
>
> So you "simplified" the C++ side, but you didn't do anything on the
> Delphi side?
>
> > procedure aMyProcedure(a : integer;b : integer;PM : PTMyMethod);
stdcall;
> > begin
> > PTMyMethod^(a,b);
>
> Do you mean PM^(a,b)?
>
> > end;
> >
> > calling the Dll function in this way:
> >
> > ...
> > FuncDll( aMyObject.aMyMethod);
>
> In your C++ code, FuncDll is declared to take two parameters. Here
> you've only passed it one. That's going to cause problems no matter what
> the rest of your code is.
>
> > Well, before to use this way to work, i tried a little code avoiding the
> > Dll, to check how
> > to use the pointers to methods, to make it "traveling" fine between
> > functions, so i just used a
> > little code in delphi. In fact all worked already fine with other types
of
> > pointers (between Delphi
> > and my Dll) that i had to use in the last days.
> >
> > The little experimental code in Delphi is :
> >
> >
> > ....
> >
> > procedure TForm1.App(a : integer);
> > var pSelf : Pointer;
> > begin
> > pSelf := Self; //only for debug goal
> >
> > if (Self.Height < 543) or (pSelf = Pointer(52)) then
>
> If this App method is supposed to be a do-nothing method merely to let | |