我在dll想對我主程序傳進去的一個數組賦值﹐便用了如下操作﹕
dll中的函數定義﹕function getdata(sn:pchar;var a:array of myrecord):boolean; //myrecord是我自己定義的記錄類型我在主程序中調用它: var b:array[1..10] of myrecord; str1:pchar;
......
if getdata(str1,b)=true then
.....運行后程序提示出錯﹕Project Project1.exe raised exception class EInvalidPointer with message 'Invalid pointer operation'. Process stopped. Use Step or Run to continue.不知道哪位高人能指點一下
dll中的函數定義﹕function getdata(sn:pchar;var a:array of myrecord):boolean; //myrecord是我自己定義的記錄類型我在主程序中調用它: var b:array[1..10] of myrecord; str1:pchar;
......
if getdata(str1,b)=true then
.....運行后程序提示出錯﹕Project Project1.exe raised exception class EInvalidPointer with message 'Invalid pointer operation'. Process stopped. Use Step or Run to continue.不知道哪位高人能指點一下
str1是PChar类型,实际就是指针,该指针指向谁呢?可能没有实际的存储空间与之对应。
修改建议:
1、定义字符数组 CharArray:Array[0..200] Of Char;
2、为str1赋值:str1:=@CharArray; 或 str1:=PChar(@harArray);
3、函数调用:if getdata(str1,b)=true then
str1:=pchar(edit1.text);
if getdata(str1,b)=true then
改成
if getdata(pchar(edit1.text),b) then
试试?2. 原因可能出在 getdata(sn:pchar;var a:array of myrecord):boolean; 调用协议上,
在动态库和调用程序声明中加上 stdcall; 试试?
function getdata(sn:pchar;var a:array of myrecord):boolean; stdcall;3. var a:array of myrecord 可能有问题, 改为 a: Pmyrecord 试试?
Pmyrecord = ^myrecord;
建議改為如下:
type
Tmyrecord = array of myrecord;
PMyRecord = ^MyRecord;dll中的函數定義改為﹕
function getdata(sn:pchar;var a: PMyRecord):boolean; stdcall;調用如下:
if getdata(str1,@b)=true then