关于在DLL中封装窗体的问题 ( 积分: 100 )

  • 主题发起人 主题发起人 newfood123
  • 开始时间 开始时间
N

newfood123

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用DLL封装一个选择窗体,用户双击后就返加一个字符串到我数据库窗体的EDIT上,要求在我的数据库窗体上传一个adoquery给DLL窗体,DLL窗体中相应的查询信息也用数据库应用程序中的adoquery,我试过,用adoquery传递老是出错,有没有高手能帮我解决一下??
 
报什么错?<br>可以在dll中定义tadoquery,不作为参数传给dll.
 
DLL返回字符串的,必须得转换,否则会直接报错的,,<br>uses&nbsp;&nbsp;delphiMM
 
function&nbsp;selectform(fieldname,tablename:string;adoc:tADOConnection):string;stdcall;<br>&nbsp;var<br>&nbsp;&nbsp;selectfm:Tselectfm;<br>begin<br>selectfm:=Tselectfm.Create(Application);<br>selectfm.query.Connection:=adoc;<br>selectfm.ds.DataSet:=selectfm.query;<br>selectfm.tablename:=tablename;<br>selectfm.fieldname:=fieldname;<br>try<br>&nbsp;selectfm.ShowModal;<br>result:=selectfm.oth;<br>finally<br>&nbsp;&nbsp;FreeAndnil(selectfm);<br>end;<br>end;<br><br><br>以上是我在DLL中定义的函数,这个能传递吗??怎么传递都是出错呢??
 
为什么总是有人不看这样一段注释???<br><br>library&nbsp;Project1;<br><br>[green]{&nbsp;Important&nbsp;note&nbsp;about&nbsp;DLL&nbsp;memory&nbsp;management:&nbsp;ShareMem&nbsp;must&nbsp;be&nbsp;the<br>&nbsp;&nbsp;first&nbsp;unit&nbsp;in&nbsp;your&nbsp;library's&nbsp;USES&nbsp;clause&nbsp;AND&nbsp;your&nbsp;project's&nbsp;(select<br>&nbsp;&nbsp;Project-View&nbsp;Source)&nbsp;USES&nbsp;clause&nbsp;if&nbsp;your&nbsp;DLL&nbsp;exports&nbsp;any&nbsp;procedures&nbsp;or<br>&nbsp;&nbsp;functions&nbsp;that&nbsp;pass&nbsp;strings&nbsp;as&nbsp;parameters&nbsp;or&nbsp;function&nbsp;results.&nbsp;This<br>&nbsp;&nbsp;applies&nbsp;to&nbsp;all&nbsp;strings&nbsp;passed&nbsp;to&nbsp;and&nbsp;from&nbsp;your&nbsp;DLL--even&nbsp;those&nbsp;that<br>&nbsp;&nbsp;are&nbsp;nested&nbsp;in&nbsp;records&nbsp;and&nbsp;classes.&nbsp;ShareMem&nbsp;is&nbsp;the&nbsp;interface&nbsp;unit&nbsp;to<br>&nbsp;&nbsp;the&nbsp;BORLNDMM.DLL&nbsp;shared&nbsp;memory&nbsp;manager,&nbsp;which&nbsp;must&nbsp;be&nbsp;deployed&nbsp;along<br>&nbsp;&nbsp;with&nbsp;your&nbsp;DLL.&nbsp;To&nbsp;avoid&nbsp;using&nbsp;BORLNDMM.DLL,&nbsp;pass&nbsp;string&nbsp;information<br>&nbsp;&nbsp;using&nbsp;PChar&nbsp;or&nbsp;ShortString&nbsp;parameters.&nbsp;}[/green]<br><br>uses<br>&nbsp;&nbsp;SysUtils,<br>&nbsp;&nbsp;Classes;<br><br>{$R&nbsp;*.res}<br><br>begin<br>end.
 
不知道怎么解决,关注ing
 
dll给dephi用可以用string<br>但是要包含shareMem单元<br>如果要通用,比如给vc调用那么还是用PChar或CharArray传递
 
各位大虾,有没有会的呢&gt;&gt;我该怎么做呢??
 
作成&nbsp;&nbsp;类com&nbsp;接口直接传过去
 
1.调用者和被调用者的工程单元的&nbsp;Use&nbsp;都要第一个引用&nbsp;ShareMem&nbsp;单元。<br>2.要在&nbsp;selectform&nbsp;函数添加代码<br>begin<br>&nbsp;&nbsp;CoInitialize(nil);<br>......<br>&nbsp;&nbsp;CoUninitialize;<br>end;
 
Delphi调用DLL窗体的演示源码<br>http://www.programbbs.com/code/105.htm
 
做成COM类传递,这个我不会,用CoInitialize(nil);时不知道期定义,各位有没能什么好的例程,上面的函数经过我修改之后可以传递,但重复调用两次后就出错了,不知道怎么解决
 
clientdataset,datasetprovider,传递variant行
 
上面说的不太明白,我在家改了程式,基本上符合了我的要求,调用DLL也正常,关闭DLL也正常(我是采用静态调用),可问题又出来了,当关闭DLL时,会出现一个这样的错误&quot;应用程序发生异常,未知的软件异常(0x0eedfade),位置为0x7c812a5b,单击确认后显示runtime&nbsp;error&nbsp;217&nbsp;at&nbsp;004A2808,在DELPHI中调试时显示&quot;invalid&nbsp;pointer&nbsp;operation&quot;好像是这指针错误,有没有人能帮我解决这个问题,先谢谢了
 
留下&nbsp;EMail&nbsp;,我发一个&nbsp;Demo&nbsp;给你吧。
 
楼上的可以给我一分吗?谢谢,了,<br>gshksh032@163.com
 
楼上已发送。
 
我的邮箱是newfood123@163.com,先谢谢了
 
怎么没有高手来解决我的问题呀??小弟请你们啦
 
用指针&nbsp;PADOQ&nbsp;=&nbsp;^TADOQuery;<br>Function&nbsp;CalSQL(ASQL:&nbsp;String;&nbsp;Const&nbsp;AADOQ:&nbsp;PADOQ&nbsp;=&nbsp;Nil):&nbsp;Integer;<br><br>Procedure&nbsp;BBBB;<br>Var<br>&nbsp;&nbsp;TempADOQ:&nbsp;TADOQuery;<br>&nbsp;&nbsp;SQLStr:&nbsp;String;<br>&nbsp;&nbsp;VNo:&nbsp;Integer;<br>Begin<br>&nbsp;&nbsp;TempADOQ&nbsp;:=&nbsp;TADOQuery.Create(Nil);<br>&nbsp;&nbsp;SQLStr&nbsp;:=&nbsp;'SELECT&nbsp;aaa&nbsp;FROM&nbsp;CCC';<br>&nbsp;&nbsp;Try<br>&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;CalSQL(SQLStr,&nbsp;@TempADOQ)&nbsp;&gt;&nbsp;0&nbsp;Then<br>&nbsp;&nbsp;&nbsp;&nbsp;Begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TempADOQ.First;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;While&nbsp;Not&nbsp;TempADOQ.Eof&nbsp;Do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VNo&nbsp;:=&nbsp;TempADOQ.FieldByName('aaa').AsInteger;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TempADOQ.Next;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End;<br>&nbsp;&nbsp;&nbsp;&nbsp;End;<br>&nbsp;&nbsp;Finally<br>&nbsp;&nbsp;&nbsp;&nbsp;TempADOQ.Close;<br>&nbsp;&nbsp;&nbsp;&nbsp;FreeAndNil(TempADOQ);<br>&nbsp;&nbsp;End;<br>End;
 
后退
顶部