Обновите Indy9 до Indy10

Я хочу обновить свое приложение с Indy 9 до 10 с помощью Delphi 2007. В этом потоке есть вызов 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;

person Roland Bengtsson    schedule 11.01.2010    source источник


Ответы (1)


у вас есть метод с таким же именем

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;
person Runner    schedule 11.01.2010
comment
Это запись, см. Обновление, но она содержит только целые числа. Может быть, я могу привести его к типу TIdBytes или скопировать его в другой буфер типа TIdBytes? - person Roland Bengtsson; 11.01.2010
comment
К вашему сведению, в Indy 10 есть функции RawToBytes () и BytesToRaw () для преобразования значений TIdBytes из / в необработанные блоки памяти. - person Remy Lebeau; 13.01.2010