想写个dll库,里面会使用TClientSocket,但不用TFORM怎样使用?

weige250 2014-11-12 02:14:11
之前用TClientSocket都是把这个控件放在form上使用,

现在想写个dll库,纯粹执行socket的连接,数据收发,不要界面显示,该怎样做?
...全文
738 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
kwer 2015-08-31
  • 打赏
  • 举报
回复
这个不算事吧,放到data module 里面,然后DLL调用DM.Create 就可以了
lyhoo163 2014-11-14
  • 打赏
  • 举报
回复
还有一种方式: 1、将TClientSocket放在调用DLL的Form上; 2、Dll通过共用内存,调用From上的 TClientSocket;
xiexuan2007 2014-11-14
  • 打赏
  • 举报
回复
用这种方式创建看也 TClientDataSet.Create(Application);
Playmaster 2014-11-14
  • 打赏
  • 举报
回复
引用 9 楼 weige250 的回复:
调用dll的工程里,引用时,没加stdcall导致
嗯,有可能
weige250 2014-11-14
  • 打赏
  • 举报
回复
调用dll的工程里,引用时,没加stdcall导致
s11ss 2014-11-13
  • 打赏
  • 举报
回复
function connectphone(port: integer):boolean;stdcall;export; begin Csocket :=TClientSocket.Create(nil); csocket.Free; result :=true; end; 不使用Csocket了才释放啊,怎么刚创建就释放了啊。。。
Playmaster 2014-11-13
  • 打赏
  • 举报
回复
引用 5 楼 weige250 的回复:
[quote=引用 4 楼 Playmaster 的回复:] 你就在dll中把创建,接收,发送,关闭函数暴露给调用者就行了,不必把tclientsocket暴露出来。 在你的创建接收发送关闭函数里使用tclientsocket处理通讯就行了。
我把这段代码放在函数connectphone里也是不行啊 var Csocket: TClientSocket;[/quote] 这应该是别的地方引起的问题。你检查一下其他代码。 Csocket应该是个dll中全局变量,这样在dll中的多个函数都可以使用,或者创建个单例模式的类。
lyhoo163 2014-11-12
  • 打赏
  • 举报
回复
From也可放入Dll中。
weige250 2014-11-12
  • 打赏
  • 举报
回复
引用 4 楼 Playmaster 的回复:
你就在dll中把创建,接收,发送,关闭函数暴露给调用者就行了,不必把tclientsocket暴露出来。 在你的创建接收发送关闭函数里使用tclientsocket处理通讯就行了。
我把这段代码放在函数connectphone里也是不行啊 var Csocket: TClientSocket;
Playmaster 2014-11-12
  • 打赏
  • 举报
回复
你就在dll中把创建,接收,发送,关闭函数暴露给调用者就行了,不必把tclientsocket暴露出来。 在你的创建接收发送关闭函数里使用tclientsocket处理通讯就行了。
weige250 2014-11-12
  • 打赏
  • 举报
回复
江湖救急啊。。。。。。。。。。。
weige250 2014-11-12
  • 打赏
  • 举报
回复
引用 1 楼 s11ss 的回复:
o:=TClientSocket.Create(nil); .... o.Free;
我根据你说的,好像不行啊,调用的时候提示Access violation at address 0311.... write of address 0000008c unit socketunit; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.Win.ScktComp, SHELLAPI, Web.Win.Sockets, Vcl.ExtCtrls; var Csocket: TClientSocket; function connectphone(port: integer):boolean;stdcall;export implementation function connectphone(port: integer):boolean;stdcall;export; begin Csocket :=TClientSocket.Create(nil); csocket.Free; result :=true; end; end. library landidll; { 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 System.SysUtils, System.Classes, windows, messages, socketunit in 'socketunit.pas'; {$R *.res} exports connectphone; begin end.
s11ss 2014-11-12
  • 打赏
  • 举报
回复
o:=TClientSocket.Create(nil); .... o.Free;

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧