You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Indy 9转Indy 10代码适配求助:Delphi游戏服务端移植报错

Indy 9 转 Indy 10 代码适配方案

针对你遇到的Indy版本兼容问题,核心修改点是Indy10将原TIdTCPConnection的IO操作方法迁移到了IOHandler属性下,以下是适配后的完整代码:

适配后的 Map_ServerExecute 方法

procedure aServer.Map_ServerExecute(AThread: TIdContext);
var
  i, n: integer;
  sz: integer;
  incom_buf: array[0..8192] of byte;
  str: string;
begin
  for i := 0 to max_connects do
    if Assigned(map_connections[i]) then
      if map_connections[i] = AThread then break;
  n := i;
  if i >= max_connects then exit;
  for i := 0 to 8191 do
    incom_buf[i] := 0;
  // Indy10中通过IOHandler调用网络读取方法
  sz := AThread.Connection.IOHandler.ReadFromStack();
  AThread.Connection.IOHandler.ReadBuffer(incom_buf, sz);
  decrypt_pkt(incom_buf, sz);
  if do_debug_output <> 0 then
  begin
    str := ByteArrayToHexString(incom_buf, sz-1);
    Writeln('in>'+str);
  end;
  sv_callback(n, 1, sz, @incom_buf[0]);
end;

适配后的 write_to_n 方法

procedure write_to_n(n: integer; is_map: integer; sz: integer; p:pointer); stdcall;
var
  TheThread: TIdContext; 
  i: integer;
  out_buf: array [0..2048] of byte;
  p_out_buf: PByteArray;
  str: string;
begin
  if n < 0 then exit;
  if n > max_connects then exit; 
  if sz <= 0 then exit;
  TheThread := nil;
  if is_map = 0 then
    TheThread := chr_connections[n]
  else 
    TheThread := map_connections[n];
  if not Assigned(TheThread) then exit;
  for i := 0 to 2048 do
    out_buf[i] := 0;
  p_out_buf := p;
  for i := 0 to sz do
    out_buf[i] := p_out_buf[i];
  if do_debug_output <> 0 then
  begin
    str := ByteArrayToHexString(out_buf, sz-1);
    Writeln('out>'+str);
  end;
  decrypt_pkt(out_buf, sz);
  // Indy10中通过IOHandler调用网络写入方法
  TheThread.Connection.IOHandler.WriteBuffer(out_buf, sz-1);
end;

关键修改说明

  • Indy10重构了网络IO架构,原TIdTCPConnection直接提供的ReadFromStack、ReadBuffer、WriteBuffer方法,现在需要通过Connection.IOHandler属性调用
  • 无需修改其他业务逻辑,仅调整网络操作的调用路径即可完成兼容
  • 确保RAD Studio项目已正确引用Indy10的核心单元(如IdTCPConnection、IdIOHandler),通常默认会自动引用

内容的提问来源于stack exchange,提问作者Meskanova Gin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 15:50:15