From: marcov@stack.nl   
      
   On 2004-12-23, eselk@surfbest.net wrote:   
      
   (this group is not abotu Delphi, but about its dos predecessor. Delphi   
   groups have "delphi" in them)   
      
   > Say I have a PAS unit with a class that has a function, something like   
   > this:   
   >   
   > procedure TfrDesignerForm.CopyToClipboard;   
   >   
   > If I want to change the behavior of this function, which isn't virtual,   
   > and I don't want to modify the source code, or maybe I want to do   
   > things that cannot be done in pascal, like work with C++ objects. What   
      
   Afaik Delphi can use C++ objects.   
      
   > I've been doing is declaring the same function in one of my C++   
   > modules, like this:   
   >   
   > void __fastcall TfrDesignerForm::CopyToClipboard(void)   
   >   
   > Then I can do whatever I want to this function in my C++ code, and as   
   > long as the C++ module comes before the PAS unit in the linking   
   > process, the C++ version of the function will be used instead of the   
   > pascal version.   
   >   
   > Is this safe?   
      
   No idea. I don't think so, but I'm not sure. It is a ugly++ construct.   
      
   > Don't pascal and C++ use the stack differently, among   
   > other possible issues?   
      
   There is a difference between a language and a compiler. A language doesn't   
   have a fixed calling conventions (but might have some constraints on them)   
      
   However traditionally most there is some difference between the avg Pascal   
   and C compiler, but that is only default behaviour. Calling convention   
   directives (in Delphi: register,cdecl, stdcall) fix this. I assume   
   __fastcall is the C++ variant of "register;", so that should be ok.   
      
   > I would think it isn't safe, now that I give it more though, but since   
   > I've been getting away with this for a couple years now, under heavy   
   > usage, maybe it is safe... or I've just been really lucky. I've used this   
   > for several functions, including several that have various calling params   
   > and also return values.   
      
   I think it is dangerous, but don't know enough of BCB to be sure. Try to make   
   a test   
   where some Delphi method writes a field of a class, and try to retrieve that   
   field using   
   the C++ method. Also put a printf or showmessage or so in the C++ method so   
   that you can   
   notice that it is actually executed.   
      
   If that works, it should be somewhat safe, as long as you stick to the same   
   compiler(versions)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|