Results 1 to 7 of 7

Thread: Library interfaces in pascal

  1. #1

    Library interfaces in pascal

    Hey,

    I've had a discussion recently, with a friend of mine, which ended with the question: "How can you write an interface for an object-oriented library in pascal".

    In C/C++, you have separate *.h and *.cpp files. If you want to distribute your library, you compile your code and you just distribute the binaries and the *.h header files.

    But In pascal, everything (interface and implementation) is combined into one file. So, you have to do it in a different way.

    Let's say someone writes a totally awesome object-oriented library in C++. Someone else would like to make pascal headers for this, but how? Pascal classes and C++ classes aren't compatible. Would the only option be to write a C++ wrapper that flattens all OOP to a C-style kind of interface (like dglOpenGL.pas), and have pascal code link against that wrapper?

    Thanks.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #2

    Re: Library interfaces in pascal

    Until the cppclass FPC extension becomes a reality then yes, the only sane way is to write a C interface
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3

    Re: Library interfaces in pascal

    If you're talking about DLL libraries, then there's probably no way to implement Pascal headers.
    But if the source code is available, there's absolutely no problem to convert the code.

  4. #4

    Re: Library interfaces in pascal

    Let's say someone writes a totally awesome object-oriented library in C++. Someone else would like to make pascal headers for this, but how? Pascal classes and C++ classes aren't compatible.
    There is a interesting article about how to use C++ clases into delphi,

    http://www.rvelthuis.de/articles/articles-cppobjs.html

    But its is always required a DLL as Delphi's linker cant link c++ .OBJ.

  5. #5

    Re: Library interfaces in pascal

    Wow.. cool... Thanks for that link
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  6. #6
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Re: Library interfaces in pascal

    afaik c++ and pascal "interfaces" are compatible.
    NecroSOFT - End of line -

  7. #7

    Re: Library interfaces in pascal

    afaik c++ and pascal "interfaces" are compatible.
    That's true. Otherwise, the current DX headers for pascal wouldn't work.

    Do note, that it's alot more work to write and maintain interfaces for all the classes you want to export. Also, you have to deal with the lifecycle issue (COM interfaces have reference counting, which can cause problems when objects are deleted). All in all, I don't think it's the nicest way of interfacing with a dynamic library. I'd rather just use classes.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •