自己写了一个数学矩阵运算函数相关的dll,在dll初始是声明如下:
type
Vector = array of double;type
Matrix2= array of array of double;然后写了一个简单的测试函数
……写了些求矩阵转置,逆等相关函数,但未对外声明。
function test(inff:Matrix2):Double; stdcall;
begin
result := inff[0,0];
end;建立了一个工程Project1
引入dll文件
function test(inff:Matrix2):Double; stdcall;
external 'dllexample.dll';
添加一个按钮,按纽事件如下:procedure Tfmtest.Button4Click(Sender: TObject);
var
tin:Matrix2;
outff:Double;
begin
SetLength(tin,4,2);
tin[0,0]:=0.5;tin[0,1]:=1;
tin[1,0]:=-1;tin[1,1]:=-1;
tin[2,0]:=-1;tin[2,1]:=0.5;
tin[3,1]:=0.5;tin[3,2]:=-1; outff:=test(tin);
Button4.Caption := FloatToStr(outff);
end;调用时出现"Invalid Pointer Operation"错误,但按钮的值已经改变为0.5。
设置断点,程序出错在“Button4.Caption := FloatToStr(outff);”这句。
不知道为什么,上网找了很多,但是大致都是说在dll中引用了string之类会出现这样的错误,我的dll中没有涉及到任何字符方面的使用,全是数值计算,而且我一开始就将ShareMem单元放在第一个引用单元。
还请高手指点迷津
type
Vector = array of double;type
Matrix2= array of array of double;然后写了一个简单的测试函数
……写了些求矩阵转置,逆等相关函数,但未对外声明。
function test(inff:Matrix2):Double; stdcall;
begin
result := inff[0,0];
end;建立了一个工程Project1
引入dll文件
function test(inff:Matrix2):Double; stdcall;
external 'dllexample.dll';
添加一个按钮,按纽事件如下:procedure Tfmtest.Button4Click(Sender: TObject);
var
tin:Matrix2;
outff:Double;
begin
SetLength(tin,4,2);
tin[0,0]:=0.5;tin[0,1]:=1;
tin[1,0]:=-1;tin[1,1]:=-1;
tin[2,0]:=-1;tin[2,1]:=0.5;
tin[3,1]:=0.5;tin[3,2]:=-1; outff:=test(tin);
Button4.Caption := FloatToStr(outff);
end;调用时出现"Invalid Pointer Operation"错误,但按钮的值已经改变为0.5。
设置断点,程序出错在“Button4.Caption := FloatToStr(outff);”这句。
不知道为什么,上网找了很多,但是大致都是说在dll中引用了string之类会出现这样的错误,我的dll中没有涉及到任何字符方面的使用,全是数值计算,而且我一开始就将ShareMem单元放在第一个引用单元。
还请高手指点迷津
解决方案 »
- 百分求助啊!!怎么保存WebBrowser里的图片
- 请教关于intraweb里面的一个dayamodulepool控件
- 关于auHTTP.dcu文件
- bde的bug?
- 怎样知道按下的键是delete键。在线等待
- 如何操作在New Items对话框中,选择File->New命令,并打开带有项目名称的页?
- 如何使用dalphi程序编写·网页游戏多开的浏览器···
- 急!!!'alter table ##new_xstj add column :a float '; 是否支持参数??????
- 如何写效验字符串是汉字的函数
- 征:在Delphi中建立Access数据库的例程?
- 怎样判断与SQL数据库连接是否断线
- DBgridEH如何把格式设成财务记账凭证的表格式
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;type
Vector = array of double; type
Matrix2= array of array of double;var
Form1: TForm1;
function test(inff:Matrix2):Double; stdcall;
external 'dllexample.dll';
implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);
var
tin:Matrix2;
outff:Double;
begin
SetLength(tin,4,2);
tin[0,0]:=0.5;tin[0,1]:=1;
tin[1,0]:=-1;tin[1,1]:=-1;
tin[2,0]:=-1;tin[2,1]:=0.5;
tin[3,1]:=0.5;tin[3,2]:=-1; outff:=test(tin);
btn1.Caption := FloatToStr(outff);
end;end.library Project1;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes;type
Vector = array of double;type
Matrix2 = array of array of double;{$R *.res}function test(inff:Matrix2):Double; stdcall;
begin
result := inff[0,0];
end; exports
test;begin
end.
单独建立一个工程,添加一个按钮,写下如下代码,出现“Invalid Pointer Operation”错误。
不知道为什么
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Matrix2= array of array of double;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
tin:Matrix2;
fin:Matrix2;
rrr,temp,tem:Double;
hehe:Double;
begin
SetLength(tin,4,2);
SetLength(fin,1,2);
tin[0,0]:=0.5;tin[0,1]:=1;
tin[1,0]:=-1;tin[1,1]:=-1;
tin[2,0]:=-1;tin[2,1]:=0.5;
tin[3,1]:=0.5;tin[3,2]:=-1;
fin[0,0]:=0.5;fin[0,1]:=1;
hehe := tin[0,0];
hehe:=hehe+1;
Button1.Caption := FloatToStr(hehe);
end;end.