Solved

Include C code in Delphi

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now