请教dll的问题!(200分)

  • 主题发起人 主题发起人 zc79
  • 开始时间 开始时间
Z

zc79

Unregistered / Unconfirmed
GUEST, unregistred user!
[:)]写了一个Main.dll文件.如下<br>library Main;<br>uses<br>&nbsp; SysUtils,<br>&nbsp; Classes;<br>{$R *.res}<br>function editsql(sql1:string;sql2:string;sql3:string;sql4:string;sql5:string;sql:string):string;stdcall;<br>&nbsp; begin<br>&nbsp; &nbsp; if sql1&lt;&gt;'' then<br>&nbsp; &nbsp; &nbsp; sql:=sql+''+' and 客户名称='+sql1;<br>&nbsp; &nbsp; if sql2&lt;&gt;'' then<br>&nbsp; &nbsp; &nbsp; sql:=sql+''+' and 料号='+sql2+'%''';<br>&nbsp; &nbsp; if sql3&lt;&gt;'' then<br>&nbsp; &nbsp; &nbsp; sql:=sql+''+' and 加工要求'+sql3;<br>&nbsp; &nbsp; if sql4&lt;&gt;'' then<br>&nbsp; &nbsp; &nbsp; sql:=sql+''+' and 脚距'+sql4;<br>&nbsp; &nbsp; if sql5&lt;&gt;'' then<br>&nbsp; &nbsp; &nbsp; sql:=sql+''+' and 工程票号'+sql5;<br>&nbsp; &nbsp; &nbsp; result:=sql;<br>&nbsp; end;<br>exports<br>&nbsp; editsql index 1;<br>begin<br>end.<br>一个主程序,工程文件源代码如下,调用上面的dll文件.运行时,如果在edit1中输入客户的名称,假如是'小明',<br>则会出现'参数'小明'没有默认值的错误,请问如何修改.谢谢!<br>unit Unit1;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, Grids, DBGrids, StdCtrls;<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Edit2: TEdit;<br>&nbsp; &nbsp; Edit3: TEdit;<br>&nbsp; &nbsp; Edit4: TEdit;<br>&nbsp; &nbsp; ComboBox1: TComboBox;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; DBGrid1: TDBGrid;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br>var<br>&nbsp; Form1: TForm1;<br>implementation<br>uses Unit2;<br>function editsql(sql1:string;sql2:string;sql3:string;sql4:string;sql5:string;sql:string):string;stdcall;external'd:/New/Main.dll';<br>{$R *.dfm}<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp;with datamodule2.ClientDataSet1 do<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;close;<br>&nbsp; &nbsp; &nbsp;commandtext:=editsql(edit1.Text,edit2.Text,edit3.Text,edit4.Text,combobox1.Text,'select 客户名称,料号 from product1 where 包装&gt;0');<br>&nbsp; &nbsp; &nbsp;execute;<br>end;<br>end;<br><br>end.<br>
 
兄弟,DLL里面涉及到输出接口的函数请不要用String,而是要用PChar。再试试吧,祝你好运!
 
用string,要加上sharemem单元。但是最好是用pchar
 

Similar threads

I
回复
0
查看
687
import
I
I
回复
0
查看
720
import
I
I
回复
0
查看
762
import
I
后退
顶部