Solved

Include C code in Delphi

Posted on 2006-11-24
3
269 Views
Last Modified: 2013-11-18
Is it possible to include C code directly in Delphi?  Similar to the situation where one can directly include assembler code.  If so, how?
0
Comment
Question by:cfm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 75 total points
ID: 18006805
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
Remarks

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.
0
 
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 50 total points
ID: 18007042
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...
0
 
LVL 28

Expert Comment

by:2266180
ID: 18025887
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 ;) )
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
creating threads in delphi 1 163
Adding a hidden div to each row in a table 6 99
Base1 Encode/Decode 3 86
Firemonkey android show image from resource ? 1 56
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question