Delphi XE 和 Winsock
我正在将我的应用程序从 Delphi 2007 升级到 Delphi XE。我有我个人编写的 Socket 组件。在新环境(XE)中它不能正常工作。相同的代码在 Delphi 2007 中工作。
这是我的代码片段:
uses WinSock;
procedure TForm1.GetProtocolClick(Sender: TObject);
var
ProtoEnt: PProtoEnt;
FProtocol: Integer;
begin
FProtocol := IPPROTO_TCP;
ProtoEnt := getprotobynumber(FProtocol);
if Assigned(ProtoEnt)
then ShowMessage(ProtoEnt.p_name);
end;
var
WSAData: TWSAData;
procedure Startup;
begin
if WSAStartup($0101, WSAData) <> 0
then raise Exception.Create('WSAStartup');
end;
procedure Cleanup;
begin
if WSACleanup <> 0
then raise Exception.Create('WSACleanup');
end;
initialization
Startup;
finalization
Cleanup;
end.
ProtoEnt 始终未分配(即 = nil)!!!!
为什么?
我要疯了才能解决这个问题...... 谢谢恩佐
I'm upgrading my application from Delphi 2007 to Delphi XE. I have my personal written Socket component. In the new environment (XE) it is not working properly. The same code works in Delphi 2007.
Here's my code fragment:
uses WinSock;
procedure TForm1.GetProtocolClick(Sender: TObject);
var
ProtoEnt: PProtoEnt;
FProtocol: Integer;
begin
FProtocol := IPPROTO_TCP;
ProtoEnt := getprotobynumber(FProtocol);
if Assigned(ProtoEnt)
then ShowMessage(ProtoEnt.p_name);
end;
var
WSAData: TWSAData;
procedure Startup;
begin
if WSAStartup($0101, WSAData) <> 0
then raise Exception.Create('WSAStartup');
end;
procedure Cleanup;
begin
if WSACleanup <> 0
then raise Exception.Create('WSACleanup');
end;
initialization
Startup;
finalization
Cleanup;
end.
ProtoEnt is always not Assigned (i.e. = nil)!!!!!
WHY?
I am going crazy to solve this problem...
Thanks
Enzo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您稍微更改一下代码,
您将看到错误代码;之后检查 WinSock 错误代码
我尝试了下一个,它在 XE 上完美运行:
If you change your code a bit
you will see error code; after that check the WinSock error codes
I tried the next, it works perfectly on XE: