我现在写了一个C语言的接口:
#ifdef MONTITOR_DLL_EXPORT
#define MONITOR_EXPORT __declspec(dllexport)
#else
#define MONITOR_EXPORT __declspec(dllimport)
#endifextern "C"
{
MONITOR_EXPORT int HelloWorld(int age);
}我的DLL名称是abc.dll我现在想在Delphi中调用这个接口,我先把DLL文件拷贝到Delphi的工程里面,然后申明如下:
type
function HelloWorld(int age):integer;cdecl;external 'abc.dll';然后在
procedure TForm2.Button1Click(Sender: TObject);
var
t : integer;
m : integer;
begin
t := 10;
m := HelloWorld(t);
end;但是这样做报错了:[DCC Error] Unit1.pas(63): E2169 Field definition not allowed after methods or properties
请问是什么原因呢?
#ifdef MONTITOR_DLL_EXPORT
#define MONITOR_EXPORT __declspec(dllexport)
#else
#define MONITOR_EXPORT __declspec(dllimport)
#endifextern "C"
{
MONITOR_EXPORT int HelloWorld(int age);
}我的DLL名称是abc.dll我现在想在Delphi中调用这个接口,我先把DLL文件拷贝到Delphi的工程里面,然后申明如下:
type
function HelloWorld(int age):integer;cdecl;external 'abc.dll';然后在
procedure TForm2.Button1Click(Sender: TObject);
var
t : integer;
m : integer;
begin
t := 10;
m := HelloWorld(t);
end;但是这样做报错了:[DCC Error] Unit1.pas(63): E2169 Field definition not allowed after methods or properties
请问是什么原因呢?
解决方案 »
- AUTOEXEC.BAT文件不会自动启动
- 使用path创建不规则窗口时发生的问题
- 救急啊,字符串的简单问题
- 我要用Delphi开发一套计算机自动组卷系统,各位手头有什么资料、建议???
- //(x,i:Integer;bBands:TQRBand);这里定义了有什么用的下面写代码的时候有什么用
- VC++中的 char 在delphi中是pchar吗?
- 大家认为PB和DELPHI在写数据库程序时谁更好一些?
- delphi+sql 2000 如何实现在delphi程序中添加修改SQL里面的表单,还有如何结合两者创建报表
- XE4 File not found DBSumLst.dcu
- 我的程序员大本营光盘的delphi版里有一个abc系列的控件!
- 窗口尺寸变化时,子窗口也跟着变化
- 全部家当97分求问:FASTREPORT打印部分内容/DBGridEh的滚动条会失效/事物是不是必须用SQL语句来操作数据库才有用等几个问题
function HelloWorld(age: integer):integer;cdecl;external 'abc.dll';请问你的QQ,多少?我加你
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm2 = class(TForm)
ExchangeIsTradeDay: TComboBox;
StaticText1: TStaticText;
StaticText2: TStaticText;
IsTradeDayEdit: TEdit;
ButtonIsTradeDay: TButton;
StaticText3: TStaticText;
Edit2: TEdit;
StaticText4: TStaticText;
ComboBox2: TComboBox;
StaticText5: TStaticText;
Edit3: TEdit;
Button2: TButton;
StaticText6: TStaticText;
Edit4: TEdit;
StaticText7: TStaticText;
ComboBox3: TComboBox;
StaticText8: TStaticText;
Edit5: TEdit;
Button3: TButton;
StaticText9: TStaticText;
Edit6: TEdit;
StaticText10: TStaticText;
Edit7: TEdit;
StaticText11: TStaticText;
StaticText12: TStaticText;
ComboBox4: TComboBox;
Button4: TButton;
StaticText13: TStaticText;
ListBox1: TListBox;
StaticText14: TStaticText;
ListBox2: TListBox;
StaticText15: TStaticText;
ListBox3: TListBox;
StaticText16: TStaticText;
ComboBox5: TComboBox;
Button5: TButton;
StaticText17: TStaticText;
StaticText18: TStaticText;
StaticText19: TStaticText;
ListBox4: TListBox;
ListBox5: TListBox;
ListBox6: TListBox;
StaticText20: TStaticText;
ComboBox6: TComboBox;
Button6: TButton;
ListBox7: TListBox;
ListBox8: TListBox;
StaticText21: TStaticText;
StaticText22: TStaticText;
StaticText23: TStaticText;
ListBox9: TListBox;
StaticText24: TStaticText;
function HelloWord(m: integer):integer;cdecl;external 'abc.dll'
function CheckStringIsNumber(date: string):boolean;
procedure ButtonIsTradeDayClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}function TForm2.CheckStringIsNumber(date: string):boolean;
var
I: integer;
begin
for I := 1 to length(date) do
begin
if(date[i] < '0') or (date[i] > '9') then
begin
Result := false;
exit;
end;
end;
Result := true;
end;procedure TForm2.ButtonIsTradeDayClick(Sender: TObject);
var
Exchange : string;
Date : string;
temp : integer;
begin
Exchange := ExchangeIsTradeDay.Text;
Date := IsTradeDayEdit.Text;
if length(Date) <> 8 then
begin
showmessage('输入的日期不正确!');
exit;
end;
if not CheckStringIsNumber(Date) then
begin
showmessage('输入的日期不正确!');
exit;
end;
temp := HelloWord(100);end;end.
声明地方是:
function HelloWord(m: integer):integer;cdecl;external 'abc.dll'
Form2: TForm2;声明不要放类里面。