在执行到LSloadPData语句时出现错误提示“An Illegal NULL Pointer was passed as an argument”信息窗口,咨询过dll技术支持他认为错误发生在b,类型相同参数c和b是连续出现在参数中,什么错误原因他也不知道,让我再咨询DELPHI专家,不胜感激!
 
1.UNIT1源码
 
{  A Delphi programming example of interfacing with the CPL API.}
 
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
uses CPL;
 {$R *.dfm}
 
////////////////////////////////////////////////////////////////////////////////
//         A simple error checker
//
procedure  ErrorCheck (nEnv: Integer; nErr: Integer);
var
   strErr : Array[0..255] of char;
begin
 
   if (nErr <> LSERR_NO_ERROR) then
   begin
      LSgetErrorMessage(nEnv, nErr, strErr);
      ShowMessage(strErr);
      halt;
   end;
end;
 procedure TForm1.Button1Click(Sender: TObject);
var con_type : pChar;
    szLicence : string;
    nEnv      : integer ;
    errorcode  : integer;
    i         : integer;
    m         : integer;
    n         : integer;
    nz        : integer;
    prob      : integer;
    Abegcol   : array of Integer;
    Arowndx   : array of Integer;
    Acoef     : array of Double;
    c         : array of Double;
    b         : array of Double;
    obj       : array of Double;
    x         : array[0..2] of Double;
    adL       : array of Double;
    adU       : array of Double;
    acAcols   : array of integer; begin
   //'number of constraints
  m := 3 ;
 
  //'number of variables
  n := 2 ;
 
  //'objective coefficients
  SetLength(c, n);
  c[0] := 20;
  c[1] := 30;
 
  //'right-hand-sides of constraints
  SetLength(b, m);
  b[0] := 120;
  b[1] := 60;
  b[2] := 50;
 
  //'constraint types
  con_type := 'LLL';
 
  //'index of first nonzero in each column
  SetLength(Abegcol, n+1);
  Abegcol[0] := 0;
  Abegcol[1] := 2;
  Abegcol[2] := 4;
 
  //'number of nonzeros in constraint matrix
  nz := 4;
 
  //'the nonzero coefficients
  SetLength(Acoef, nz);
  Acoef[0] := 1;
  Acoef[1] := 1;
  Acoef[2] := 2;
  Acoef[3] := 1;
 
  //'the row indices of the nonzeros
  SetLength(Arowndx, nz);
  Arowndx[0] := 0;
  Arowndx[1] := 1;
  Arowndx[2] := 0;
  Arowndx[3] := 2;
 
  SetLength(adL, 1);
  adL[0] := 0;
  SetLength(adU, 1);
  adU[0] := 0;
  SetLength(acAcols, 1);
  acAcols[0] := 0;
 
  //下面是出错的语句
    errorcode := LSloadLPData(prob, m, n, LS_MAX, 0, c[0], b[0], con_type, nz, Abegcol[0], acAcols[0],Acoef[0], Arowndx[0], adL, adU);   ErrorCheck(nEnv, errorCode);
 
end;
 
end.
 
2.CPL单元LSloadLPData定义
 
function  LSloadLPData (    nModel :  Integer; 
                         nCons :  Integer; 
                         nVars :  Integer; 
                         dObjSense :  Integer; 
                         dObjConst :  Double; 
                     Var adC : Array of  Double; 
                     Var adB : Array of  Double;
                         szConTypes :  pChar; 
                         nAnnz :  Integer; 
                     Var aiAcols : Array of  Integer; 
                     Var acAcols : Integer; 
                     Var adAcoef : Array of  Double; 
                     Var aiArows : Array of  Integer; 
                     Var adL : Array of  Double; 
                     Var adU : Array of  Double) : Integer; stdCall; external 'CPL.dll';3.CPL.DLL中的LSloadLPData定义
 
LSloadPData(pLSmode pModel,int nCons,int nVars,int dObjsense,double dObjconst,double *padC,double *padB,char *pachContypes,int nAnnz,int *paiAcols,int *pacAcols,double *padAcoef,int *paiArows,double *padL,double *padU)