Mega Code Archive

 
Categories / Delphi / Ide Indy
 

Calls to Qt cause installation problems for components in Kylix BCB IDE

Title: Calls to Qt cause installation problems for components in Kylix BCB IDE Question: If a component written in Delphi makes a call to Qt, installing the component in the Kylix BCB IDE can be difficult. This article describes how to overcome this problem Answer: I had problems with a component I wrote that used calls to Qt. The procedure that caused the problems wrote 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 worked just fine in the Kylix Delphi IDE. but it wouldn't compile with the Kylix C++ IDE. The error messages were [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 could 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 could get components that worked in either IDE by declaring a virtual, abstract procedure and then declaring two new components - one for each IDE - and overriding the abstract procedure with the code that works in that IDE. However, if you want to use visual form inheritance in the C++ IDE to inherit from forms created in the Delphi IDE, this doesn't work. I could view such forms in the IDE but when I tried to compile the project, it reported linker errors. This appeared to be because the Delphi and C++ versions of the component really weren't the same thing even though they had 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. My final solution was to install the component in the C++ IDE as a package Select Component|Install Packages Click the Add... Button. Select a *.so file generated by the Delphi IDE. Click the Open button. Click the OK button. For each package, you need to generate an *.a file. File|CloseAll File|New|Other|Library File|Save Project As and save with the same root name as the Package file for the Delphi IDE Project|Add to Project Select the *.so file. File | Save All Now you are ready to actually build the library, so: Project | Build Click the OK button. For each source file you also need to generate an *.hpp file. You can do this by adding the Object Pascal source file to a package and trying to compile the package. Even though, it may not be possible to compile the Object Pascal source file in the C++ IDE, an *.hpp file will still be generated. File|Close All File|New|Other|Package File|Save Project As and save with any name but in the same directory as the component source file. Project|Add to Project Select the Object Pascal file. Click the Compile button on the Package dialog box. Click the Make button. It is not necessary to click the install button too. If an Object Pascal component has been changed, it may need to be removed from the C++ IDE and then added back to it to get it to function correctly. It may also be necessary, to generate new *.a and *.hpp files. The Open Edition of Kylix will not create *.a files in this manner. However, you can still install and use your components if you uncheck the "Build with runtime packages" checkbox in the "Component|Install Packages" dialog box.