Include C code in Delphi

Is it possible to include C code directly in Delphi?  Similar to the situation where one can directly include assembler code.  If so, how?
Who is Participating?
2266180Connect With a Mentor Commented:
not that I know of (maybe in bds2006, though I doubt it)
but you can link obj files. so you compile C code into objs and then inlude them via {$L theobjfile.obj}
quote from delphi help:
Type    Parameter
Syntax    {$L filename}{$LINK filename}
Scope    Local

The $L parameter instructs the compiler to link the named file with the program or unit being compiled. The $L directive is used to link with code written in other languages for procedures and functions declared to be external. The named file must be an Intel relocatable object file (.OBJ file). The default extension for filename is .OBJ. If filename does not specify a directory path, then, in addition to searching for the file in the same directory as the current module, Delphi searches in the directories specified in the Search path input box on the Directories/Conditionals page of the Project|Options dialog box (or in the directories specified in the -O option on the DCC32 command line).

To specify a file name that includes a space, surround the file name with single quotation marks: {$L 'My file'}.
For further details about linking with assembly language, see online Help.
Wim ten BrinkConnect With a Mentor Self-employed developerCommented:
Not directly, no. Unless you start using Borland C++Builder (Part of Codegear Development Studio 2006) and mix C++ sources with Pascal sources. But it also means your main project file will be a C++ file, not a Pascal file.

Ciuly provided the other solution, by linking the *.obj resources generated by the C++ compiler but you might need to include a few more *.obj files if your C++ code relies on some other sourcefiles. (And in the worst case, you'd need to include the whole C++ runtime library.)

Alternative solution? Wrap the C++ code in a DLL...
let me see if I get it correctly:
you didn't get the answer you expected and that is why you gave us a B?

you know, you must keep in mind that even if you don't like the solution, if you get the best solution possible (read again, I said solution) then you should give an A. The grade shows how much correct the answer is AND how good the solution is. If you give a B, that means insatisfactory. But the problem here is not that the solutino is insatisfactory, but the development environment.
How would you like me to post a question: "Is it possible to design planes and vehicles in delphi?" you say, no, that is not possible. you need something else like blabla. and then I give you B because that just doesn't satisfy me.

I'm not sure if you are subscribed to the EE newsletter. if not, you should. often there is mentioned about grading and choosing the right answer and stuff like this (with reference to the help and FAQ and some other resources; which by the way, you should read: good pointers there ;) ). So often it happens that the askers (and experts) are getting a tip from the moderators, and for the askers it is often said that if you are not satisfied with the answer, try to get better results from the experts involved.

it is in your best interest to get the best anwser from us. It is in our best interest to get the highest grade. So it's your right to ask more questions, to ask for more information, etc. AND we expect this as this is a feedback for us to know that we need to do a little more for you. And in the end, everybody is happy.

(note: this post wants to inlfuence the future. past can remain as it is. I prefer telling such thing to people so that they take it into consideration in the future. And they usually do :) Not everybody knows how to optimally work on EE ;) )
All Courses

From novice to tech pro — start learning today.