以下代码编译通过,但调用并执行之后出错,请大家帮忙。
library item_search;{ 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,
  windows,
  dialogs,
  forms,
  module2Unit in 'module2Unit.pas' {DataModule2: TDataModule};type
  Tsearch_record=record
      item_fnamedll,item_fmodeldll,item_fmeasuredll,itemneed_outdll:string;
      end;
function itemneed(var form_numberdll:integer;itemneed_indll:pchar):Tsearch_record;stdcall;
begin
//messagebox(0,'form_numberdll','itemneed_indll=',mb_ok);
showmessage('form_numberdll='+pchar(form_numberdll));
case form_numberdll of
      2:
      begin
datamodule2.item_qr.Close;
datamodule2.item_qr.SQL.Clear;
datamodule2.item_qr.SQL.Add('SELECT fnumber,fname FROM t_Department WHERE fnumber=:number' );
datamodule2.item_qr.Parameters.ParamValues['number']:=string(itemneed_indll);
datamodule2.item_qr.Open;
if datamodule2.item_qr.FieldByName('fname').AsString<>'' then
beginresult.itemneed_outdll:=datamodule2.item_qr.FieldByName('fname').Value;
itemneed_indll:='';
end;
if datamodule2.item_qr.FieldByName('fname').AsString='' then
begin
showmessage('编制部门不能为空!!!');
itemneed_indll:='';
result.itemneed_outdll:='';
end;
      end;
      3:
            begin
datamodule2.item_qr.Close;
datamodule2.item_qr.SQL.Clear;
datamodule2.item_qr.SQL.Add('SELECT fnumber,fname FROM t_emp WHERE fnumber=:number' );
datamodule2.item_qr.Parameters.ParamValues['number']:=string(itemneed_indll);
datamodule2.item_qr.Open;if datamodule2.item_qr.FieldByName('fname').AsString<>'' then
begin
result.itemneed_outdll:=datamodule2.item_qr.FieldByName('fname').AsString ;
itemneed_indll:='';
end;
if datamodule2.item_qr.FieldByName('fname').AsString='' then
begin
showmessage('职员不能为空!!!');
itemneed_indll:='';
result.itemneed_outdll:='';
end;
      end;
      4:
            begin
            showmessage('5');
datamodule2.item_qr.Close;
showmessage('4');
datamodule2.item_qr.SQL.Clear;
datamodule2.item_qr.SQL.Add('SELECT fnumber,fname,fmodel,funitid FROM t_icitem WHERE fnumber=:number' );
datamodule2.item_qr.Parameters.ParamValues['number']:=string(itemneed_indll);
showmessage('2');
datamodule2.item_qr.Open;
if datamodule2.item_qr.FieldByName('fname').AsString<>'' then
begin
showmessage('3');
//添加单位
datamodule2.qr.Close;
datamodule2.qr.SQL.Clear;
datamodule2.qr.SQL.Add('SELECT * FROM t_MeasureUnit WHERE FMeasureUnitID =:id');
datamodule2.qr.Parameters.ParamValues['id']:=datamodule2.item_qr.FieldValues['funitid'];
datamodule2.qr.Open;
result.item_fnamedll:=datamodule2.item_qr.FieldByName('fname').AsString ;
result.item_fmodeldll:=datamodule2.item_qr.FieldByName('fmodel').AsString ;
result.item_fmeasuredll:=datamodule2.qr.FieldByName('fname').AsString ;
itemneed_indll:='';
 end;
if datamodule2.item_qr.FieldByName('fname').AsString='' then
begin
// 释放全局变量
result.item_fnamedll:='';
result.item_fmodeldll:='';
result.item_fmeasuredll:='';
showmessage('物料不能为空!!!');
itemneed_indll:='';
result.itemneed_outdll:='';
end;
showmessage('itemneed_indll='+itemneed_indll);
form_numberdll:=0;
       end;
      end;
      end;
      exports
       itemneed;
      {$R *.res}begin
end.