OpenMotif and Lazarus? lazarus / 13-General ---------------------------------------------------------------------- guest · 2006-05-31 17:40 Is it possible to write a openmotif/motif widget aplication using Lazarus? For example under FreeBSD system? ---------------------------------------------------------------------- felipemdc · 2006-05-31 20:34 You mean you want to use the form designed to write a motif application, or you just want a pascal software that called motif functions by code? To write a free pascal software that uses motif, first you need to translate openmotif c headers to pascal. This is easy, only takes some time. Then you can use lazarus to write a pascal program that calls motif functions. If you need help translating the headers, don´t hesitate to ask. To use the form designer one needs to write a new interface for Lazarus, so you can use Delphi classes (such as TBitmap, TForm, TLabel, etc), and they will be conected to motif by the interface. Before you write the interface you also need to translate the headers to pascal. There is a tutorial to create a new lazarus interface here: http://wiki.lazarus.freepascal.org/index.php/LCL_Internals ---------------------------------------------------------------------- Anonymous · 2006-05-31 22:14 I have never translated headers before but this seems quite hard. Isn't there any script or program to convert headers automatically? By the way... Do I need to translate all the headers of the openmotif or only the ones needed? [ps: sorry, I am a moderator and I mistakenly edited your post instead of writing an answer =( The "edit" button is very close to the "quote" button] ---------------------------------------------------------------------- Anonymous · 2006-05-31 22:40 Here is an example frame.h from motif. Could someone show me please how to translate this short header to Lazarus (pascal) one? ---------------------------------------------------------------------- ------------------------------ #ifndef _XmFrame_h #define _XmFrame_h #include #ifdef __cplusplus extern "C" { #endif #ifndef XmIsFrame #define XmIsFrame(w) XtIsSubclass(w, xmFrameWidgetClass) #endif /* XmIsFrame */ /* Class record constants */ externalref WidgetClass xmFrameWidgetClass; typedef struct _XmFrameClassRec * XmFrameWidgetClass; typedef struct _XmFrameRec      * XmFrameWidget; /********    Public Function Declarations    ********/ extern Widget XmCreateFrame(                         Widget parent,                         char *name,                         ArgList arglist,                         Cardinal argcount) ; /********    End Public Function Declarations    ********/ #ifdef __cplusplus }  /* Close scope of 'extern "C"' declaration which encloses file. */ #endif #endif /* _XmFrame_h */ /* DON'T ADD ANYTHING AFTER THIS #endif */ ---------------------------------------------------------------------- felipemdc · 2006-05-31 23:17 First you need to take a strategical decision here. Will you convert every file into a unit or create one main unit with many include files? An example a binding with one main unit (in fact two) and many include files is PascalMagick bindings for ImageMagick. You can download it here: http://sourceforge.net/project/showfiles.php?group_id=92177&pack age_id=174103 It contains both c headers and pascal headers, so you can easely compare them. Now, is frame.h a main file that should become a unit or just a small include file? Assuming frame.h will become frame.inc (a include file), it would be like this: //#include ----> remember to add Xm unit to the main unit where this file belongs to {Careful with this macro: #ifndef XmIsFrame #define XmIsFrame(w) XtIsSubclass(w, xmFrameWidgetClass) #endif } { Class record constants } //externalref WidgetClass xmFrameWidgetClass; type   XmFrameWidgetClass: ^_XmFrameClassRec;   XmFrameWidget: ^_XmFrameRec; {******** Public Function Declarations ********} function XmCreateFrame( parent: Widget; name: PChar; _arglist: ArgList; argcount: Cardinal): Widget; cdecl; external MotifExport; -------------- On the main unit you will need to declare MotifExport: const   WandExport = 'libMotif'; // substitute with real lib name Please take a look at wand/magick_wand.pas on PascalMagick bindings to see how a main unit of a binding looks like. You can also compare it with the equivalente .h file ---------------------------------------------------------------------- felipemdc · 2006-05-31 23:25 > I have never translated headers before but this seems quite hard. Not really =) After a while it get´s quite easy. Everything is hard on the first time. > Isn't there any script or program to convert headers automatically? Yes, a program that comes with Free Pascal called h2pas can convert headers. But my personal experience was that it didn´t work to me due to macros, strange ways to declare things it cannot understand, etc. > By the way... Do I need to translate all the headers of the openmotif or only the ones needed? Only the ones you need, but try to make it extensible. Just coment things you don´t want to convert so someone can convert them on the future. And try to keep things in the same order as on the c files so in the future someone can add missing things more easely. ---------------------------------------------------------------------- Marc · 2006-06-01 10:32 there are also some conversion tools which convert headers in one go. If you translater the motif (or lesstif?) headers then they can maybe added to the fpc packages. Ask the fpc-devel mailinglist for more info on how to convert. ---------------------------------------------------------------------- felipemdc · 2006-06-02 00:12 As an extra information, here is a guide about importing c libraries on pascal software: http://www.drbob42.com/delphi/headconv.htm Can be very useful. ---------------------------------------------------------------------- Mathias · 2023-04-02 16:10 I know the post is a bit old, but it still belongs here. I took the trouble and translated Openmotif. Today I translated the last header. I just wanted to try and see if I could translate a library of headers. I think it will still have bugs for sure, but it just got finished today. If you want, you can try it out, simply install the following package. The Athena widgets are also included. https://github.com/sechshelme/Lazarus-Motif_Athena_Widget https://github.com/sechshelme/Lazarus- Motif_Athena_Widget/tree/main/Motif_Athena_Package