一个Double型数组需要以实参形式传入一个函数,该函数的形参应该如何定义?
我是这样做的:
x: array[1..10] of double;
function abc(y: pdouble):extended:stdcall;
var
i:integer;
total:doubel;
begin
……
total:=0;
for i:=1 to 10 do
total:=total+y[i]; <-编译出错
end;
编译出错,说Array type required.该怎么做才不会出错?
我是这样做的:
x: array[1..10] of double;
function abc(y: pdouble):extended:stdcall;
var
i:integer;
total:doubel;
begin
……
total:=0;
for i:=1 to 10 do
total:=total+y[i]; <-编译出错
end;
编译出错,说Array type required.该怎么做才不会出错?
上面是手误。
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
x :array [1..10] of double;
public
{ Public declarations }
function abc(x :PDouble):extended;stdcall;
end;var
Form1: TForm1;implementation{$R *.DFM}
function TForm1.abc(x :PDouble):Extended;stdcall;
begin
ShowMessage('´«µÝ³É¹¦!');
end;procedure TForm1.FormCreate(Sender: TObject);
begin
abc(@x);
end;end.
Pdouble=arrary[1..10 of double;
//定义pdouble类型,为一个含有10个元素的Double数组
x: array[1..10] of double;
function abc(y:pdouble):extended:stdcall;
var
i:integer;
total:double;
begin
……
total:=0;
for i:=1 to 10 do
total:=total+y[i]; <-编译出错
end;
好像不行啊!
你的函数虽然可以编译通过,但是在函数调用的时候会出现类型不匹配的问题啊!实参是Pointer型的,而形参是PDouble型的。
调用方法:abc(@x);