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
Solved

Include C code in Delphi

Posted on 2006-11-24
3
268 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tidtcpserver connection lost handle 2 101
How to replace a token in a string with square brackets? 2 75
cookies analysis tools 2 100
Multi-layered image in FireMonkey 9 48
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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 …

808 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