我正在使用Embarcadero RAD Studio XE2 Update 4以及随附的Indy软件包。Delphi XE2 TIdUDPClient ReceiveString过载不起作用
我的意图是在局域网中找到一台服务器,并使用来自TIdUDPClient的广播,等待服务器获取其IP的响应。如果我使用没有参数的TIdUDPClient方法ReceiveString,接收数据就可以正常工作。
但是当我尝试使用RAD Studio附带的Indy 10 Documentation版本10.5.8.3中发现的重载版本时,它不会编译并显示'E2250:'ReceiveString'没有重载版本,可以是用这些参数调用'。 这里是我的代码:
unit Client;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPClient, Vcl.StdCtrls, IdGlobal;
type
TFormLC = class(TForm)
UDPClient: TIdUDPClient;
LServer: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
FormLC: TFormLC;
implementation
{$R *.dfm}
function findServer:string;
var ans, ip : string;
port: TIdPort;
begin
with FormLC.UDPClient do begin
Active := True;
BroadcastEnabled:=True;
Broadcast('ServerRequest', 1234);
ans := ReceiveString(ip, port);
Active := False;
end;
if SameText(ans, 'ServerAccept') then
result := ip
else
result := '';
end;
procedure TFormLC.Button1Click(Sender: TObject);
var ans:string;
begin
LServer.Caption := findServer;
end;
end.
我注意到,印的online documentation从自带的IDE的文档不同,试了一下在那里所述,无更迭。
任何帮助将是伟大的!
肯定摆脱'with with'语句 –
+1:没有更多'with' –
谢谢!这有很大帮助! –