我今天学习使用DLL,有这样一个问题,大家帮我分析一下,是那儿的错。
结构是这样的,有一个接口单位(import.pas),主要做用是声明一个数据类型,还有引用DLL文件然后是DLL文件,中有一个函数,作用是将小写人民币转换大写的。然后在一个顶目的窗体中调用DLL中的函数。一切都正常,只是在最后窗体关闭时,有一个错误提示
如下:Project rmb.exe raised exception class EInvalidPointer with message'Invalid pointer operation'.Process stop......
我找不出来问题,大家帮我一下,以下是源文件:
//import.pas
unit import;interface
uses ShareMem,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;
type
    PRMB=^RMB;
    RMB=record
    yi:integer;
    qw:integer;
    bw:integer;
    sw:integer;
    wa:integer;
    qian:integer;
    bai:integer;
    shi:integer;
    ge:integer;
    jiao:integer;
    fen:integer;
    resultstring:string;
    end;
var ChinaMoney:array [0..9] of string=('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
    ChinaUnit:array [1..11] of string=('亿','千万','百万','十万','万','千','百','十','元','角','分');
function ToChinaUnit(money:double;cmoney:PRMB):double;stdcall;
implementation
function ToChinaUnit;external 'dlltormb.dll' name 'ToChinaUnit';
end.//dlltormb.dpr
library dlltormb;
uses
  ShareMem,SysUtils,Classes,import,math;{$R *.res}
function ToChinaUnit(money:double;cmoney:PRMB):double;stdcall;
var temp:int64;
begin
     result:=money;
     money:=roundto(money,-2);
     temp:=strtoint(floattostr(money*100));
     with Cmoney^ do
        begin
            yi:=temp div 10000000000;
            temp:=temp mod 10000000000;
            qw:=temp div 1000000000;
            temp:=temp mod 1000000000;
            bw:=temp div 100000000;
            temp:=temp mod 100000000;
            sw:=temp div 10000000;
            temp:=temp mod 10000000;
            wa:=temp div 1000000;
            temp:=temp mod 1000000;
            qian:=temp div 100000;
            temp:=temp mod 100000;
            bai:=temp div 10000;
            temp:=temp mod 10000;
            shi:=temp div 1000;
            temp:=temp mod 1000;
            ge:=temp div 100;
            temp:=temp mod 100;
            jiao:=temp div 10;
            fen:=temp mod 10;
            resultstring:='';
            if yi>0 then
               resultstring:=resultstring+ChinaMoney[yi]+ChinaUnit[1];
            if qw>0 then
               resultstring:=resultstring+ChinaMoney[qw]+ChinaUnit[2];
            if bw>0 then
               resultstring:=resultstring+ChinaMoney[bw]+ChinaUnit[3];
            if sw>0 then
               resultstring:=resultstring+ChinaMoney[sw]+chinaUnit[4];
            if wa>0 then
               resultstring:=resultstring+ChinaMoney[wa]+chinaUnit[5];
            if qian>0 then
               resultstring:=resultstring+ChinaMoney[qian]+ChinaUnit[6];
            if bai>0 then
               resultstring:=resultstring+ChinaMoney[bai]+ChinaUnit[7];
            if shi>0 then
               resultstring:=resultstring+ChinaMoney[shi]+ChinaUnit[8];
            if ge>0 then
               resultstring:=resultstring+ChinaMoney[ge]+ChinaUnit[9];
            if jiao>0 then
               resultstring:=resultstring+ChinaMoney[jiao]+ChinaUnit[10];
            if fen>0 then
               resultstring:=resultstring+ChinaMoney[fen]+ChinaUnit[11];
        end;
end;exports
   ToChinaUnit;end.
//mainfrm.pas
unit mainfrm;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,math;type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;implementation
uses import;
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var money:double;
    cmoney:RMB;
begin
    money:=strtofloat(edit1.text);
    money:=ToChinaUnit(money,@cmoney);
    label2.Caption:=cmoney.resultstring;
end;end.