德尔福XE3:使用多个C头文件和源文件 [英] Delphi XE3: Using multiple C headers and source files

查看:153
本文介绍了德尔福XE3:使用多个C头文件和源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一组相互依赖的.c和.h文件的,而且我想弄清楚究竟是如何C / C ++ - 到帕斯卡尔的工作(我的德尔福/帕斯卡尔的工作,否则是pretty基本) 。的C文件是一种数学算法的步骤1-N(按顺序)(每个人都是一个独立的功能),一个头指定每个功能使用的变量(我使用记录来重新创建德尔福的.h文件),另一头细节自定义变量类型。我们的目标是访问的功能,而无需重新编写的C code到帕斯卡尔/德尔福的语法,德尔福code链接到一些现有的C。有我剪断了太多冗长的文件(12 .c和4·H),和我的C是可怕的生疏,但我会尽力。

So, I have a set of interdependent .c and .h files, and I'm trying to figure out exactly how C/C++-to-Pascal works (my delphi/pascal work otherwise was pretty basic). The c files are steps 1-N (in order) of a mathematical algorithm (each one is a separate function), one header specifies the variables used in each function (I'm using record to recreate the .h files in delphi), and the other header details a custom variable type. The goal is to access the functions without having to re-write the C code into Pascal/Delphi syntax, linking from delphi code to some existing c. There are too many lengthy files (12 .c and 4 .h) for me to snip, and my C is horribly rusty, but I'll try.

例如,我有一个文件的 funcs.h

For example, I have a file funcs.h:

#ifndef _FUNCS_H
#ifndef _FUNCS_H

#ifdef __cplusplus
extern "C" {
#endif

#include "New_Type.h"  // custom variable used in funcs.h
#include "Optional.h"  // optional set of more functions

typedef struct {
    int a1[4];
    double b1[10];

    // Computed if optional functions are requested
    double c1[10];
    int d1[4];
} func1;

typedef struct {
    new_type c2, d2;
} func2;
}
#endif
#endif

和上述变量的文件 func1.c func2.c 做一些数学运算(主要是线性代数)。我的眼前的问题是:

and files func1.c and func2.c do some mathematical manipulation (mostly linear algebra) of the above variables. My immediate questions are:


  1. 请我需要多个德尔福文件,就像有多个C头文件?

  2. 什么做的Delphi文件的骨架的样子(premable,函数调用)?

  3. 什么是{$​​ LINKLIB c}里,CDECL,和回调?他们在其他问题/常见的答案我见过

也许我需要改变我的搜索/问题,但我真的不知道如何正确地问这个。我并不需要一个明确的答案,说实话我preFER如果有人可以点我的一些链接(见鬼了一本书:我将使用在未来这种语言),我真的AP preciate吧。

Maybe I need to change my search/question, but I'm honestly not sure how to properly ask this. I don't need a specific answer, honestly I'd prefer if someone could point me to some links (heck a book: I'll be using this language in the future), I'd really appreciate it.

在此先感谢所有帮助。

推荐答案

与#2启动:在Delphi中,无论是头部和实现在同一文件中去。因此,这里的一类表示将你的头的东西(.H)和​​实现的东西(.C)将适用于在Delphi单位/文件结构的基本框架。

Starting with #2: In Delp both the header and the implementation go in the same file. So here's a basic skeleton of a class showing where your header stuff (.h) and implementation stuff (.c) will fit into the structure of a unit/file in Delphi.

unit Unit1;

interface
  uses // List of header dependencies goes here...
  // Stuff from the .h file will go here
implementation
  uses // List of implementation dependencies goes here...
  // Stuff from the .c file will go here
end.

返回#1:这不是严格必要有一个1:你的C头文件的Delphi文件1映射,但如果是用C每个文件粒度的一个良好的水平,这是可能将在Delphi同样锻炼。除非你有一个很好的理由去改变它,我会离开他们在同一C头文件映射到一个Delphi文件。

Back to #1: It's not strictly necessary to have a 1:1 mapping of your C header files to Delphi files, but if that was a good level of granularity per file in C, it's probably going to work out similarly in Delphi. Unless you have a good reason to change it, I'd leave them mapped at one C header file to one Delphi file.

About.com对Delphi开发,该页面,例如,在与单元可能是在了解一个Delphi文件结构的一个很好的起点工作。我也发现自己使用 DelphiBasics 作为参考网站很多(虽然它更针对超过结构的方法) 。绝对不打折Embarcadero公司网站上的官方文档。他们语言指南部分实际上是学习德尔福的教科书,并有足够的详细,获得语言的基础。

About.com has a pretty detailed section on Delphi development, the page, for example, on working with units could be a good starting point on learning about the structure of a Delphi file. I also find myself using DelphiBasics as a reference site a lot (though it's more aimed at methods than structures). And definitely do not discount the official documentation on Embarcadero's website. Their Language Guide section is practically a textbook on learning Delp and is sufficiently detailed to get the fundamentals of the language.

,然后尽可能#3:这可以很容易地在堆栈溢出几个独立完整的问题,如果你想更深入。但总的来说,这听起来像你正在寻找code直接从德尔福调用C code。 CDECL 是调用约定之一(即恰好匹配C的一个......),指定命令参数传递给方法哪个。了解更多关于它在英巴卡迪诺的文档 $ LINKLIB 用于(C库,而如果你调用C code你会怎么做在这种情况下)链接​​到图书馆和回调大致相当于C中的函数指针。

And then as far as #3: This could easily be several separate full questions on stack overflow if you want more depth. But in general, it sounds like you're looking at code for calling c code directly from Delphi. CDecl is one of the calling conventions (the one that happens to match c...) which specifies which order parameters are passed to methods. Read more about it in Embarcadero's documentation. $LINKLIB is used to link to a library (in this case the C library, which you would do if you're calling c code), and callback is roughly equivalent to a function pointer in c.

这是你的第三子问题的整体声音,我猜你已经对如何用C code德尔福项目的阅读了,而不必重新编写的C code到帕斯卡尔/德尔福的语法,德尔福code链接到一些现有的C库你不想重新写或转换。如果这是你的终极目标,只是链接到你的C库没有改写,这篇文章的在FreePascal的使用C可能是很好的帮助。用于连接到C code而言,FreePascal的和Delphi之间的差异,帕斯卡的两个变种,将是相对忽略不计)。基本上,你必须重新编写或C头转换成Pascal语法,使德尔福知道哪些功能是在你的C库,所以你可以给他们打电话。鲍勃博士具有良好的详细页面约在Delphi使用C动态链接库,如果你正在寻找有关转换头文件的详细信息。当中约类型名称如何搭配其他有用的信息,还有的存在转换C头文件德尔福头自动化工具,页面上的例子。它可能会更易于使用自动化的工具,你的头转换为德尔福的语法,如果你的目标仅仅是打电话或利用来自Delphi应用程序,现有C code,而不完全移植整个code语言库德尔福

From the overall sound of your third sub-question, I'm guessing you've been reading up on how to use C code in a Delphi project, without having to re-write the C code into Pascal/Delphi syntax, linking from delphi code to some existing c library you don't want to re-write or convert. If that's your ultimate goal, to just link to your C library without rewriting it, this article on using C in FreePascal may be of good help. For the purposes of linking to C code, the differences between FreePascal and Delp both variants of Pascal, are going to be relatively negligible). Basically, you have to re-write or convert the c header into Pascal syntax so that Delphi knows what functions are in your C library, so you can call them. Dr. Bob has a good detailed page about using C dlls in Delphi if you're looking for more info about converting header files. Amongst other useful information about how type names match, there is an example on that page of automated tools that exist for converting c header files to delphi headers. It may be easier to use an automated tool to convert your header to delphi syntax, if your goal is just to call or utilize your existing c code from a Delphi application without fully porting the entire code-library to Delphi.

和为例子的缘故,从你的问题,通过鲍勃博士的HeadConverter工具转换你的头,使输出是这样的:(实际输出较长,包括code加载你的c code作为一个DLL和一些意见以及)

And for the sake of example, your header from your question, converted through Dr. Bob's HeadConverter tool, gives output like this: (the actual output is longer and includes code for loading your c code as a dll and some comments as well)

unit FILE1;

interface
uses
  Windows;

{$INCLUDE "New_Type.h"}
{$INCLUDE "Optional.h"}

type
  func1 = record
    a1: Array[0..4-1] of Integer;
    b1: Array[0..10-1] of Double;
    c1: Array[0..10-1] of Double;
    d1: Array[0..4-1] of Integer;
  end {func1};

type
  func2 = record
    c2, d2: NEW_TYPE;
  end {func2};

{...}

implementation
   {...}
end.

这篇关于德尔福XE3:使用多个C头文件和源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆