[DUG] call a method function from outside object
Kyley Harris
KyleyHarris at gmail.com
Mon Jul 11 18:09:12 NZST 2005
I find it interesting that your 1..2..3 option would actually work.
Generally, when there is a single procedure callback, it is not a nested
type system,
so the minute the second form is opened and you attach Open2, the link
to Open1
no longer exists, because it can only hold one method at a time....
unless there is something missing
in what you are showing us.
I would guess that in each case of calling DllOpen, one of the 3
parameters is in someway unique, and
that is what would be used to bind to one instance of an application. ie
one component per Channel.
Then you have one global Open, and an internal list of all your
instances. depending on the parameters sent
you would locate and call a method on the correct instance variable.
regards
Ross Levis wrote:
>I've spent a lot of time trying to work out a solution and discussing it
>on other mailing lists and newsgroups and it does not appear possible.
>
>DLLOpen is declared as a standard procedure, not a method in the 3rd
>party C++ DLL, so if there are 2 instances of my component on the form,
>with 2 DLL's loaded, my component doesn't know which instance the DLL is
>calling, since a standard procedure occupies the same memory location in
>both instances of the component.
>
>I've got around the problem by creating 3 identical sets of global
>procedures and using a global incrementing integer in the constructor,
>so each new instance is given a different procedure address. The object
>instance pointers are stored in a global array so the procedure knows
>which instance of the object to work with. eg.
>
>var
> ObjCount: Integer;
> MyObjects: array[1..3] of TMyObject
>
>constructor Create;
>begin
> Inc(ObjCount);
> MyObjects[ObjCount] := Self;
> case ObjCount of
> 1: DLLOpen := Open1;
> 2: DLLOpen := Open2;
> 3: DLLOpen := Open3;
> end;
>end
>
>procedure Open1(SRate,nChan,BPS:Integer):Integer; cdecl;
>begin
> MyObjects[1].Open(SRate,nChan,BPS);
>end;
>
>procedure Open2(SRate,nChan,BPS:Integer):Integer; cdecl;
>begin
> MyObjects[2].Open(SRate,nChan,BPS);
>end;
>
>procedure Open3(SRate,nChan,BPS:Integer):Integer; cdecl;
>etc
>
>This limits the number of times a user can put my component on a form,
>but at least it works, and any more than 3 should not be necessary.
>
>It would be nice if there was some way to translate a procedure call to
>one address and map it to a different address transparently to the
>calling DLL, then it could be fully OOP. But I don't know if this is
>possible.
>
>Regards,
>Ross.
>
>----- Original Message -----
>From: <Guy.Brown at sungard.com>
>To: <delphi at ns3.123.co.nz>
>Sent: Monday, July 11, 2005 3:24 PM
>Subject: RE: [DUG] call a method function from outside object
>
>
>Hi Ross. My Delphi is a bit rusty but I believe it's just:
>
>DLLOpen := Open;
>
>Assuming that DLLOpen is declared as a procedure of object with the
>appropriate parameter list.
>
>hth
>
>Guy
>
>-----Original Message-----
>From: delphi-bounces at ns3.123.co.nz [mailto:delphi-bounces at ns3.123.co.nz]
>On Behalf Of Ross Levis
>Sent: Sunday, 3 July 2005 5:48 p.m.
>To: NZ Borland Developers Group - Delphi List
>Subject: Re: [DUG] call a method function from outside object
>
>In trying to solve this I thought of using method functions inside an
>object rather than standard functions, and then assigning the method
>pointer to the DLL, but I can't seem to do this either. eg. In a class
>procedure I do this...
>
> DLLOpen := TMethod(Open).Code; <<< Invalid typecast
>
>Open is a function defined in the same class DLLOpen is the function
>pointer defined in the DLL which I need to assign to the method pointer.
>
>I'm not sure why this doesn't work. My only other option is to use
>global variables!
>
>Regards,
>Ross.
>
>----- Original Message -----
>From: "Ross Levis" <ross at stationplaylist.com>
>To: "NZ Borland Developers Group - Delphi List" <delphi at ns3.123.co.nz>
>Sent: Sunday, July 03, 2005 4:56 PM
>Subject: [DUG] call a method function from outside object
>
>
>In a component I'm writing, a DLL needs access to a standard function so
>this is declared outside the main object. Within this function I want
>to access variables and methods inside the main object, but I can't find
>a way to do it. Is this possible?
>
>Thanks,
>Ross.
>
>_______________________________________________
>Delphi mailing list
>Delphi at ns3.123.co.nz
>http://ns3.123.co.nz/mailman/listinfo/delphi
>
>_______________________________________________
>Delphi mailing list
>Delphi at ns3.123.co.nz
>http://ns3.123.co.nz/mailman/listinfo/delphi
>
>_______________________________________________
>Delphi mailing list
>Delphi at ns3.123.co.nz
>http://ns3.123.co.nz/mailman/listinfo/delphi
>
>_______________________________________________
>Delphi mailing list
>Delphi at ns3.123.co.nz
>http://ns3.123.co.nz/mailman/listinfo/delphi
>
>
>
More information about the Delphi
mailing list