Qt incompatibilities between Pascal and C++

[email protected] Mon, 2 Dec 2002 13:44:38 -0500
Newsgroups gmane.comp.lang.delphi.kylix
Message-ID <3DEB63C6.18074.E2CCDA@localhost>
I am having problems with a component that uses calls to Qt.  I would 
appreciate any suggestions for how to solve it.  

The procedure that causes the problems writes Text at location (X,Y) 
at an angle specified by Angle using the following code.

Uses Qt, QGraphics;

procedure TRbwRuler.PaintRotated(const X, Y, Angle: double;
  const Text: string);
begin
  Canvas.Start;
  QPainter_translate(QPainterH(Canvas.Handle),X,Y);
  try
    QPainter_rotate(QPainterH(Canvas.Handle),Angle);
    try
      Canvas.TextOut(0,0,Text);
    finally
      QPainter_rotate(QPainterH(Canvas.Handle),-Angle);
    end;
  finally
    QPainter_translate(QPainterH(Canvas.Handle),-X,-Y);
    Canvas.Stop;
  end;
end;

This works just fine in the Kylix Delphi IDE. but it won't compile 
with the Kylix C++ IDE. The error messages are 

[Linker Error] Unresolved external 
'Qt::QPainter_translate(QT::QPainter *, double, double)' referenced 
from QrbwRuler.o

and 

[Linker Error] Unresolved external 'Qt::QPainter_rotate(QT::QPainter 
*, double, double)' referenced from QrbwRuler.o

I can write a similar component in the Kylic C++ IDE using code like 
this.

void __fastcall TRbwRuler::PaintRotated(const double X, const double 
Y,
  const double Angle, const AnsiString Text)
{
  Canvas->Start();
  Qt.QPainter_translate((QPainter__*)Canvas->Handle,X,Y);
  __try
  {
    Qt.QPainter_rotate((QPainter__*)Canvas->Handle,Angle);
    __try
      {
      Canvas->TextOut(0,0,Text);
      }
    __finally
      {
      Qt.QPainter_rotate((QPainter__*)Canvas->Handle,-Angle);
      };
  }
  __finally
  {
    Qt.QPainter_translate((QPainter__*)Canvas->Handle,-X,-Y);
    Canvas->Stop();
  };
}

I can get components that work in either IDE by declaring a virtual, 
abstract procedure and then declaring a two new components - one for 
each IDE - and overriding the abstract procedure with the code that 
works in that IDE.  

My problem is that I want to use visual form inheritance in the C++ 
IDE to inherit from forms created in the Delphi IDE.  This doesn't 
work.  I can view such forms in the IDE but when I try to compile the 
project, it reports linker errors.  This appears to be because the 
Delphi and C++ versions of the component really aren't the same thing 
even though they have identical names and functionality.

This is really the same sort of problem I was trying to avoid in 
creating the two components in the first place.  The C++ IDE and 
Delphi IDE _appear_ to need different versions of QPainter_translate 
and QPainter_rotate.  The Delphi IDE appears to wants the one 
declared in Qt.pas whereas the C++ IDE appears to want the one 
declared in qpainter.hb.  Nevertheless, the CLX source code seems to 
get around this somehow because QPainter_translate is used in it. For 
example, it is used in QComCtrls.pas in TCustomIconView.DoStartDrag.

I've tried to use the HPPEMIT directive to overcome this problem but 
it didn't work.

(*HPPEMIT '#include <qpainter.hb>'*)

I have also tried installing the .so file generated by the Delphi IDE 
as a package but that didn't work either.

The problem may be related to the EXTERNALSYM compiler directive 
after the declaration of QPainter_translate and QPainter_rotate in 
Qt.pas.  According to 
http://community.borland.com/soapbox/techvoyage/article/1,1795,10281,0
0.html, the EXTERNALSYM directive tells the C++Builder compiler not 
to insert identifiers back into the HPP file it is generating.

How can I write Object Pascal source code that includes calls to 
QPainter_translate and QPainter_rotate and have it compile correctly 
in both the Delphi and C++ IDE's?

[email protected]
http://www.mindspring.com/~rbwinston/rbwinsto.htm
ftp://ftp.mindspring.com/users/rbwinston/incoming


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/CBxunD/vN2EAA/xGHJAA/i7folB/TM
---------------------------------------------------------------------~->

-------------------------------------------------------
Forum / mailing list for Borland Kylix programmers
Our web page:  http://groups.yahoo.com/group/kylixgroup
To join the forum: [email protected]
To unsubscribe:  [email protected]
To post your messages:       [email protected]
To contact the moderator:  [email protected]
------------------------------------------------------- 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/