代码之家  ›  专栏  ›  技术社区  ›  Roland Bengtsson

将indy9升级到indy10

  •  0
  • Roland Bengtsson  · 技术社区  · 15 年前

    我想用Delphi2007将我的应用程序从indy 9升级到10。 在这个线程中,有一个对indy9 tidudpbase.sendbuffer的调用,但由于方法参数不存在,所以不会在indy10中编译。第三个参数abuffer是一个var参数,在indy10中没有找到任何这样的方法签名。 有其他调用方法吗?

    procedure TSenderThread.Execute;
    var
      vTimeData: TTimeDataRecord;
      I: Integer;
      FElapsed: Int64;
      FTimerElappsed,
      vLastTimerElappsed: Int64;
    begin
      vTimeData.Size := SizeOf(TTimeDataRecord);
      vTimeData.ClientCount := 1;
      Priority := tpHighest;
      FIdUDPClient := TIdUDPClient.Create(nil);
      FIdUDPClient.BroadcastEnabled := True;
      try
        while not (Terminated or Application.Terminated) do
        begin
          Sleep(1000);
          //Measure Time frame
          vLastTimerElappsed := FTimerElappsed;
          QueryPerformanceCounter(FTimerElappsed);
          FElapsed := ((FTimerElappsed-vLastTimerElappsed)*1000000) div FFrequency;
          vTimeData.TotalTimeFrame := FElapsed;
          if FRunning then
          begin
            FElapsed := ((FTimerElappsed-FStart)*1000000) div FFrequency;
            vTimeData.CurrentMessageTime := FElapsed;
          end
          else
            vTimeData.CurrentMessageTime := 0;
          //Copy Values
          vTimeData.AccumulatedTime := InterlockedExchange(TimeData.AccumulatedTime,0);
          vTimeData.MessageCount := InterlockedExchange(TimeData.MessageCount,0);
          for I := 0 to TimeClassMax do
            vTimeData.TimeClasses[I] := InterlockedExchange(TimeData.TimeClasses[I],0);
    
           // Calls procedure TIdUDPBase.SendBuffer(AHost: string; const APort: Integer; var ABuffer; const AByteCount: integer);
           // This is changed in Indy10, unable to compile  
          FIdUDPClient.SendBuffer('255.255.255.255', UIPerfPort, vTimeData, TimeData.Size);
        end;
      finally
        FreeAndNil(FIdUDPClient);
      end;
    end;
    

    编辑: vTimeData基本上是一个整数数组。

      TTimeDataRecord = record
        Size: Integer; //Size of record structure is transfered and compared for safty reasons.
        ClientCount: Integer;
        AccumulatedTime: Integer; //This is the accumulated time busy in microseconds
        CurrentMessageTime: Integer; //This is the time the current message has been processed. If several computers report a high value at the same time it indicates a freeze!
        TotalTimeFrame: Integer; //This is the total time measured in microseconds
        MessageCount: Integer;
        TimeClasses: array [0..TimeClassMax] of Integer;
      end;
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   Runner    15 年前

    你有一个同名的方法

    procedure TIdUDPClient.SendBuffer(const AHost: string; const APort: TIdPort;
      const ABuffer: TIdBytes);
    

    它不需要非类型化缓冲区,而是需要一个字节数组。你的数据是什么样的?您只需要将数据写入一个字节数组。类似:

    var
     Buffer: TIdBytes;
    begin
     SetLength(Buffer, YourSizeOfData);
     Move(YourData, Buffer[0], YourSizeOfData);
     FIdUDPClient.SendBuffer('255.255.255.255', UIPerfPort, Buffer);
    end;
    

    但正如我所说,这取决于数据的类型。不过,这种方法是可以的。

    编辑:

    现在我可以看到你有一个记录,你有两个选择:

    只需将整个记录移动到字节数组。

    Move(@aRecord, Buffer[0], (6 + TimeClassMax) * SizeOf(Integer));
    

    在记录中有一个CopyToBytes方法来执行实际的复制。我想更一般。

    TTimeDataRecord = record
      Size: Integer; //Size of record structure is transfered and compared for safty reasons.
      ClientCount: Integer;
      AccumulatedTime: Integer; //This is the accumulated time busy in microseconds
      CurrentMessageTime: Integer; //This is the time the current message has been  processed. If several computers report a high value at the same time it indicates a freeze!
      TotalTimeFrame: Integer; //This is the total time measured in microseconds
      MessageCount: Integer;
      TimeClasses: array [0..TimeClassMax] of Integer;
      procedure CopyToBytes(var Buffer: TIdBytes);
    end
    

    copytobytes的实现

    procedure TTimeDataRecord.CopyToBytes(var Buffer: TIdBytes);
    begin
      // copy the data however you see fit
    end;