dll调用的问题!(100分)

  • 主题发起人 主题发起人 ABA
  • 开始时间 开始时间
A

ABA

Unregistered / Unconfirmed
GUEST, unregistred user!
我使用该DLL,调用成功后,总是提示““Invalid Integer operation ””不知道为什么有这个错误!
 
非法整数操作?代码?
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, DB, ADODB;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; Edit2: TEdit;<br>&nbsp; &nbsp; Label2: TLabel;<br>&nbsp; &nbsp; ADOConnection1: TADOConnection;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>&nbsp; //function WoDe:Integer ;Stdcall;<br>&nbsp; function GetCurrChange(aNum: Double):String;stdcall;<br>&nbsp; function ShowMsg(aContent,aCaption:Pchar):Integer;StdCall;<br>&nbsp; function ShowQueryMsg(aContent,aCaption:Pchar):Integer;StdCall;<br>&nbsp; function GetClientName(var aConSys:TADOConnection;aClientName:String):String;StdCall;<br><br>&nbsp; //function ShowD:String;Stdcall;<br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>&nbsp; //function WoDe;External 'ShowNum.dll' name 'Wode';<br>&nbsp; function GetCurrChange;External 'CTCPubLib.dll' name 'GetCurrChange';<br>&nbsp; function ShowMsg;External 'CTCPubLib.dll' name 'ShowMsg';<br>&nbsp; function ShowQueryMsg;External 'CTCPubLib.dll' name 'ShowQueryMsg';<br>&nbsp; function GetClientName;External 'CTCPubLib.dll' name 'GetClientName'<br>//function ShowD;external 'DllTest.dll' name 'ShowD';<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; rTemp:Real;<br>begin<br>&nbsp; try<br>&nbsp; &nbsp; rTemp:=StrToFloat(self.Edit1.Text);<br>&nbsp; &nbsp; self.Edit2.text:=GetCurrChange(rTemp);<br>&nbsp; &nbsp; ShowQueryMsg('转换成功!','询问');<br>&nbsp; &nbsp; //Temp:=IntToStr(Wode);<br>&nbsp; except<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>end;<br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; //ShowMessage(GetClientName(self.ADOConnection1,inputBox('输入框','输入客户代码 ','')));<br>&nbsp; application.MessageBox(pchar(GetClientName(self.ADOConnection1,inputBox('输入框','输入客户代码 ',''))),pchar('结果'),0)<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br><br>end;<br><br>end.<br>代码如上!
 
DLL的代码:<br>{-----------------------------------------------------------------------------<br>&nbsp; Name: CTCSystem's Public Library 1.0<br>&nbsp; Author: &nbsp; &nbsp;Asutin Chan<br>&nbsp; Date: &nbsp; &nbsp; &nbsp;04-六月-2003<br>-----------------------------------------------------------------------------}<br><br>library Dll_2;<br><br>{ Important note about DLL memory management: ShareMem must be the<br>&nbsp; first unit in your library's USES clause AND your project's (select<br>&nbsp; Project-View Source) USES clause if your DLL exports any procedures or<br>&nbsp; functions that pass strings as parameters or function results. This<br>&nbsp; applies to all strings passed to and from your DLL--even those that<br>&nbsp; are nested in records and classes. ShareMem is the interface unit to<br>&nbsp; the BORLNDMM.DLL shared memory manager, which must be deployed along<br>&nbsp; with your DLL. To avoid using BORLNDMM.DLL, pass string information<br>&nbsp; using PChar or ShortString parameters. }<br><br>uses<br>&nbsp; sharemem,<br>&nbsp; SysUtils,<br>&nbsp; Classes;<br><br>{$R *.res}<br>Function CurrChange(num:Double):String;StdCall<br>const<br>&nbsp; &nbsp; szd:string = '零壹贰叁肆伍陆柒捌玖';<br>&nbsp; &nbsp; dwd:string = '分角元拾佰仟万拾佰仟亿拾佰仟';<br>&nbsp; &nbsp; kdwd:string = '零仟零佰零拾零角零分';<br>&nbsp;var<br>&nbsp; &nbsp; n1,n2,nm:shortint;<br>&nbsp; &nbsp; je,zf:string;<br>&nbsp; &nbsp; getastr:string[4];//用于临时保存一个字符<br>&nbsp; &nbsp; code,getanum:integer;<br>&nbsp; <br>begin<br>&nbsp; &nbsp;//检测数据范围 最大999999999999.99 最小0.00<br>&nbsp; If (num &gt; 999999999999.99) Or (num = 0) Or (num &lt; 0.01) Then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;CurrChange:= '';<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; End;<br>&nbsp; je:= '';<br>&nbsp; //将数字从右到左读成大写金额<br>&nbsp; str(num:15:2,zf); //将数字转换“#####.##”格式的字符格式<br>&nbsp; zf:=trim(zf);<br>&nbsp; n1 := Length(zf); &nbsp;//数字长度<br>&nbsp; n2 := 1;<br>&nbsp; &nbsp;For nm := 1 To n1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; //getastr:=;<br>&nbsp; &nbsp; &nbsp; &nbsp; If copy(zf,n1,1)&lt;&gt; '.' Then //跳过小数点<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getastr:=copy(zf, n1, 1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val(getastr,getanum,code);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getastr:=copy(szd, (getanum+1)*2 - 1, 2);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; je := getastr+copy(dwd, n2*2 - 1, 2)+ je;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n2 := n2 + 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; n1 := n1 - 1;<br>&nbsp; &nbsp; end;<br>//去掉大写金额中不符合使用习惯的部分<br>&nbsp; &nbsp;n1:= Length(je); &nbsp; &nbsp;//字符串长度<br>&nbsp; &nbsp;for nm:=1 to (n1 div 4)-1 do<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;n2:=n1-nm*4+1;<br>&nbsp; &nbsp; &nbsp; &nbsp;getastr:=copy(je,n2,n2+4);<br>&nbsp; &nbsp; &nbsp; &nbsp;if AnsiPos(getastr,kdwd)&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; je:=copy(je,1,n1-nm*4+2)+copy(je,n1-nm*4+5,length(je));<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;n1:=AnsiPos('零零',je);<br>&nbsp; &nbsp;while n1&lt;&gt;0 do<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;je:=copy(je,1,n1+1)+copy(je,n1+4,length(je));<br>&nbsp; &nbsp; &nbsp; &nbsp;n1:=AnsiPos('零零',je);<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;//当出现“零亿”,“零万”,“零元”时去掉“零”<br>&nbsp; &nbsp;n1:=AnsiPos('零亿',je);<br>&nbsp; &nbsp;if n1&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp;je:=copy(je,1,n1-1)+copy(je,n1+2,length(je));<br>&nbsp; &nbsp;n1:=AnsiPos('零万',je);<br>&nbsp; &nbsp;if n1&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp;je:=copy(je,1,n1-1)+copy(je,n1+2,length(je));<br>&nbsp; &nbsp;n1:=AnsiPos('零元',je);<br>&nbsp; &nbsp;if n1&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp;je:=copy(je,1,n1-1)+copy(je,n1+2,length(je));<br>&nbsp; &nbsp;//处理最后出现的“零”<br>&nbsp; &nbsp;n1:=length(je);<br>&nbsp; &nbsp;If copy(je,n1-1,n1)='零' Then je:=copy(je,1,n1-2);<br>&nbsp; &nbsp;n1:=length(je);<br>&nbsp; &nbsp;getastr:=copy(je,n1-1,2);<br>&nbsp; &nbsp;If getastr='元'//如果没小数部分则加“整“<br>&nbsp; &nbsp; &nbsp;Then je:=je+'整'<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; if (getastr&lt;&gt;'分') and (getastr&lt;&gt;'角') then je:=je+'元整';<br>&nbsp; &nbsp;CurrChange:= je;<br>End;<br><br>Exports<br>&nbsp; CurrChange;<br>begin<br>end.<br>
 
可能是Dll内部代码错误,把代码贴出来吧
 
这才是正确的DLL代码,刚刚那个不对!<br>{-----------------------------------------------------------------------------<br>&nbsp; Name: CTCSystem's Public Library 1.0<br>&nbsp; Author: &nbsp; &nbsp;Austin Chan<br>&nbsp; Date: &nbsp; &nbsp; &nbsp;04-六月-2003<br>-----------------------------------------------------------------------------}<br><br>library CTCPubLib;<br><br>{ Important note about DLL memory management: ShareMem must be the<br>&nbsp; first unit in your library's USES clause AND your project's (select<br>&nbsp; Project-View Source) USES clause if your DLL exports any procedures or<br>&nbsp; functions that pass strings as parameters or function results. This<br>&nbsp; applies to all strings passed to and from your DLL--even those that<br>&nbsp; are nested in records and classes. ShareMem is the interface unit to<br>&nbsp; the BORLNDMM.DLL shared memory manager, which must be deployed along<br>&nbsp; with your DLL. To avoid using BORLNDMM.DLL, pass string information<br>&nbsp; using PChar or ShortString parameters. }<br><br>uses<br>&nbsp; sharemem,<br>&nbsp; SysUtils,Forms,Windows, DB, ADODB,<br>&nbsp; Classes;<br><br>{$R *.res}<br>{<br>&nbsp; Name: GetCurrChange<br>&nbsp; Input: Money<br>&nbsp; Return: Format of Chinese(is a String Type)<br>&nbsp; Author: Austin Chan<br>&nbsp; Date: &nbsp; 04-六月-2003<br>}<br>Function GetCurrChange(aNum:Double):String;StdCall<br>const<br>&nbsp; cNumUnit:string = '零壹贰叁肆伍陆柒捌玖';<br>&nbsp; cChUnit:string = '分角元拾佰仟万拾佰仟亿拾佰仟';<br>&nbsp; cZChUnit:string = '零仟零佰零拾零角零分';<br>var<br>&nbsp; lnTemp1,lnTemp2,I:shortint;<br>&nbsp; lcStr1,lcStr2:string;<br>&nbsp; laGetStr:string[4];//用于临时保存一个字符<br>&nbsp; lnCode,laGetNum:integer;<br>&nbsp; <br>begin<br>&nbsp; &nbsp;//Is check Range of aNum &nbsp;Max:999999999999.99 Min:0.00<br>&nbsp; If (aNum &gt; 999999999999.99) Or (aNum = 0) Or (aNum &lt; 0.01) Then<br>&nbsp; begin<br>&nbsp; &nbsp; Result:= '';<br>&nbsp; &nbsp; Exit;<br>&nbsp; End;<br>&nbsp; lcStr1:= '';<br>&nbsp; //Is change the aNum To Chinese From Right To Left<br>&nbsp; str(aNum:15:2,lcStr2); //Is Change The aNum To "#####.##"<br>&nbsp; lcStr2:=trim(lcStr2);<br>&nbsp; lnTemp1 := Length(lcStr2); &nbsp;//The aNum's Length<br>&nbsp; lnTemp2 := 1;<br>&nbsp; For I := 1 To lnTemp1 do<br>&nbsp; begin<br>&nbsp; &nbsp; //getastr:=;<br>&nbsp; &nbsp; If copy(lcStr2,lnTemp1,1)&lt;&gt; '.' Then //ignore decimal<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; laGetStr:=copy(lcStr2, lnTemp1, 1);<br>&nbsp; &nbsp; &nbsp; val(laGetStr,laGetNum,lnCode);<br>&nbsp; &nbsp; &nbsp; laGetStr:=copy(cNumUnit, (laGetNum+1)*2 - 1, 2);<br>&nbsp; &nbsp; &nbsp; lcStr1 := laGetStr+copy(cChUnit, lnTemp2*2 - 1, 2)+ lcStr1;<br>&nbsp; &nbsp; &nbsp; lnTemp2 := lnTemp2 + 1;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp;lnTemp1 := lnTemp1 - 1;<br>&nbsp; end;<br><br>&nbsp; lnTemp1:= Length(lcStr1); &nbsp; &nbsp;//The lcStr1's Length<br>&nbsp; for I:=1 to (lnTemp1 div 4)-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; lnTemp2:=lnTemp1-I*4+1;<br>&nbsp; &nbsp; laGetStr:=copy(lcStr1,lnTemp2,lnTemp2+4);<br>&nbsp; &nbsp; if AnsiPos(laGetStr,cZChUnit)&lt;&gt;0 then<br>&nbsp; &nbsp; lcStr1:=copy(lcStr1,1,lnTemp1-I*4+2)+copy(lcStr1,lnTemp1-I*4+5,length(lcStr1));<br>&nbsp; end;<br>&nbsp; lnTemp1:=AnsiPos('零零',lcStr1);<br>&nbsp; while lnTemp1 &lt;&gt; 0 do<br>&nbsp; begin<br>&nbsp; &nbsp; lcStr1:=copy(lcStr1,1,lnTemp1+1)+copy(lcStr1,lnTemp1+4,length(lcStr1));<br>&nbsp; &nbsp; lnTemp1:=AnsiPos('零零',lcStr1);<br>&nbsp; end;<br>&nbsp; &nbsp;//Delete The "零" when it's bring “零亿”,“零万”,“零元”<br>&nbsp; lnTemp1:=AnsiPos('零亿',lcStr1);<br>&nbsp; if lnTemp1&lt;&gt;0 then<br>&nbsp; &nbsp; lcStr1:=copy(lcStr1,1,lnTemp1-1)+copy(lcStr1,lnTemp1+2,length(lcStr1));<br>&nbsp; lnTemp1:=AnsiPos('零万',lcStr1);<br>&nbsp; if lnTemp1&lt;&gt;0 then<br>&nbsp; &nbsp; lcStr1:=copy(lcStr1,1,lnTemp1-1)+copy(lcStr1,lnTemp1+2,length(lcStr1));<br>&nbsp; &nbsp; lnTemp1:=AnsiPos('零元',lcStr1);<br>&nbsp; &nbsp; if lnTemp1&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; lcStr1:=copy(lcStr1,1,lnTemp1-1)+copy(lcStr1,lnTemp1+2,length(lcStr1));<br>&nbsp; &nbsp;//Dispose The Last Zero<br>&nbsp; lnTemp1:=length(lcStr1);<br>&nbsp; If copy(lcStr1,lnTemp1-1,lnTemp1)='零' Then lcStr1:=copy(lcStr1,1,lnTemp1-2);<br>&nbsp; &nbsp; lnTemp1:=length(lcStr1);<br>&nbsp; &nbsp; laGetStr:=copy(lcStr1,lnTemp1-1,2);<br>&nbsp; If laGetStr='元' Then //If no part of decimal,Add "整"<br>&nbsp; &nbsp; lcStr1:=lcStr1+'整'<br>&nbsp; else<br>&nbsp; &nbsp; if (laGetStr&lt;&gt;'分') and (laGetStr&lt;&gt;'角') then<br>&nbsp; &nbsp; &nbsp; lcStr1:=lcStr1+'元整';<br>&nbsp; Result:= lcStr1;<br>End;<br>{<br>&nbsp; Name: ShowMsg<br>&nbsp; Input: Contert,Caption<br>&nbsp; Return: Integer<br>&nbsp; Author: Austin Chan<br>&nbsp; Date: &nbsp; 04-六月-2003<br>&nbsp; Desc: Information MessageBox<br>}<br>function ShowMsg(aContent,aCaption:Pchar):Integer;StdCall<br>begin<br>&nbsp; Result:=Application.MessageBox(aContent,aCaption,0);<br>end;<br>{<br>&nbsp; Name: ShowQueryMsg<br>&nbsp; Input: Contert,Caption<br>&nbsp; Return: Integer<br>&nbsp; Author: Austin Chan<br>&nbsp; Date: &nbsp; 04-六月-2003<br>&nbsp; Desc: Confirm MessageBox<br>}<br>function ShowQueryMsg(aContent,aCaption:Pchar):Integer;StdCall<br>begin<br>&nbsp; Result:=Application.MessageBox(aContent,aCaption,MB_YESNO);<br>end;<br><br>{<br>&nbsp; Name: GetClientName<br>&nbsp; Input: aConSys,aClientNo<br>&nbsp; Return: String<br>&nbsp; Author: Austin Chan<br>&nbsp; Date: &nbsp; 04-六月-2003<br>&nbsp; Desc: Get of ClientName<br>}<br>function GetClientName(var aConSys:TADOConnection;aClientNo:String):String;StdCall<br>var<br>&nbsp; ladoQuery:TADOQuery;<br>begin<br>&nbsp; ladoQuery:=TADOQuery.Create(nil);<br>&nbsp; ladoQuery.Connection:=aConSys;<br>&nbsp; with ladoQuery do<br>&nbsp; begin<br>&nbsp; &nbsp; if Active = True then Close;<br>&nbsp; &nbsp; sql.Clear;<br>&nbsp; &nbsp; sql.Add('Select ClientName From IeClient Where ClientNo=:ClientNo');<br>&nbsp; &nbsp; parameters.ParamByName('ClientNo').Value:=aClientNo;<br>&nbsp; &nbsp; open;<br><br>&nbsp; &nbsp; Result:=Trim(Fieldbyname('ClientName').AsString);<br>&nbsp; end;<br>end;<br><br>{<br>&nbsp; Name: GetPortName<br>&nbsp; Input: aConSys,aPortNo<br>&nbsp; Return: String<br>&nbsp; Author: Austin Chan<br>&nbsp; Date: &nbsp; 04-六月-2003<br>&nbsp; Desc: Get of PortName<br>}<br>function GetPortName(var aConSys:TADOConnection;aPortNo:String):String;StdCall<br>var<br>&nbsp; ladoQuery:TADOQuery;<br>begin<br>&nbsp; ladoQuery:=TADOQuery.Create(nil);<br>&nbsp; ladoQuery.Connection:=aConSys;<br>&nbsp; with ladoQuery do<br>&nbsp; begin<br>&nbsp; &nbsp; if Active = True then Close;<br>&nbsp; &nbsp; sql.Clear;<br>&nbsp; &nbsp; sql.Add('Select PortName From IePort Where PortNo=:PortNo');<br>&nbsp; &nbsp; parameters.ParamByName('PortNo').Value:=aPortNo;<br>&nbsp; &nbsp; open;<br><br>&nbsp; &nbsp; Result:=Trim(Fieldbyname('PortName').AsString);<br>&nbsp; end;<br>end;<br><br>Exports<br>&nbsp; GetCurrChange,ShowMsg,ShowQueryMsg,GetClientName,GetPortName;<br>begin<br>end.
 
&gt;&gt;function GetCurrChange(aNum: Double):String;stdcall;<br>&gt;&gt;function GetClientName(var aConSys:TADOConnection;aClientName:String):String;StdCall;<br><br>最好是返回Pchar<br>
 
可是我要在程序中使用STRING类型的,可以将PCHAR转换成STRING的吗?
 
可以的<br>
 
我用d7+xpsp1<br>你的代码正确
 
我刚刚将STRING该为PCHAR就可以了。谢谢!
 
多人接受答案了。
 
后退
顶部