0

アプリケーションを Delphi 2007 で Indy 9 から 10 にアップグレードしたいと考えています。3 番目のパラメーター 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;
4

1 に答える 1

0

同じ名前のメソッドがあります

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;

しかし、私が言ったように、それはデータのタイプに依存します。ただし、アプローチは問題ありません。

編集:

レコードがあることがわかりましたので、次の 2 つのオプションがあります。

レコード全体をバイト配列に移動するだけです。

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;
于 2010-01-11T10:52:21.867 に答える