Solved

Include C code in Delphi

Posted on 2006-11-24
3
259 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:
ciuly 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:ciuly
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 72
WordPress/WooCommerce security best practices? 2 67
Select distinct 25 60
JQuery tracking event. 3 41
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 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

11 Experts available now in Live!

Get 1:1 Help Now