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" <[EMAIL PROTECTED]>
To: <[email protected]>
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
> you confirm that the method gets called, then don't have it do weird
> things like get a pointer to Self. Do *simple* things in your functions
> (like MessageBeep, or OutputDebugString). That way, you can be confident
> that they're not interfering with the part of your program you're
> actually trying to test.
>
> > Self.Height := Self.Height div 2;
> > end;
> >
> > type TP = procedure(a : integer) of object;
> > type P_TP = ^TP;
> >
> > procedure TForm1.Button1Click(Sender: TObject);
> > var
> > m : procedure(a : integer) of object;
> > a : integer;
> > m1 : P_TP;
> > begin
> > App(0); //for debug goal
> > m := App;
> > m1 := @m;
>
> Applying a single "@" operator to a method pointer merely tells the
> compiler to treat it as a pointer instead of trying to call the method.
> Double the operator to tell Delphi you really want a pointer to the m
> variable: @@m.
>
> Also, turn on the "typed @ operator" compiler option.
>
> > a := 1027;
> >
> > m(0);
> >
> > P_TP(m1)^(a); //this call raises an exception.
>
> Which exception?
>
> --
> Rob
>
>
>
> -----------------------------------------------------
> Home page: http://groups.yahoo.com/group/delphi-en/
> To unsubscribe: [EMAIL PROTECTED]
> Yahoo! Groups Links
>
>
>
>
>
>
>
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
SPONSORED LINKS
| C programming language | Computer programming languages | Java programming language |
| The c programming language | C programming language | Concept of programming language |
YAHOO! GROUPS LINKS
- Visit your group "delphi-en" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

