Q&A

  • Packed Record에 직접 복사는 어떻게 하지요?
아래처럼 TCP수신데이터를 RcvData에 직접 복사하고 싶은데 방법을 잘 모르겠네요.
고수분들의 가르침을 부탁드립니다.
Incompatible Type.......

<!-- CodeS-->
type TRcvData = packed record
  shhp:array[0..9] of char;
  hpcrc:Word;
  start:Byte;
  rsense:Byte;
  rdlen:Word;
  seq:Word;
  fn:Byte;
  utime:DWord;
  rcontent:TByteArray;  //가변
end;

var
    RcvData: TRcvData;

procedure TWSD_Main_F.IdTCPServerExecute(AThread: TIdPeerThread);
var
  Msg : string;
  i : integer;
begin
  Msg := AThread.Connection.CurrentReadBuffer;

  //현재는 수신데이터를 Hex로 변환하여 잘라 사용하고 있슴
  for i := 1 to length(Msg) do
      resp := resp + IntToHex(Byte(Msg[i]),2);
  
  //아래는 ByteArray로 만들고 RcvData에 복사하려니까 에러가.....
  Move(resp, ByteArr[0], Length(resp));
  Move(ByteArr[0], RcvData, Length(RcvData));
end;

<!--CodeE-->
2  COMMENTS
  • Profile
    권태훈 2006.08.22 20:43
    Move(resp, ByteArr[0], Length(resp));

    resp는 변수이고, 포인터가 아니죠.
    그러니 포인터로 만들어주면 복사가 될것입니다.

    Move(@resp, ByteArr[0], Length(resp));

    근데 보니 byteArr[0]도 1바이트 변수이지 포인터가 아니네요.
    복사가 되도 값은 엉뚱한게 들어가겠죠..

    그래서

    Move(@resp, @ByteArr[0], Length(resp));

    근데, 보통이 이렇게 쓰지 않구요.

    type
      aptype = ^atype;
      atype = record
        i : integer;
      end;

    이런식으로 포인터 선언하고요

    var
      ap : aptype;

    이런식으로 포인터 변수를 선언하고요. .그 다음에 메모리에 직접 매핑하면

    굳이 새로운 메모리를 할당할 필요가 없지만,...

    버퍼에 다른 내용이 들어가면 로직이 꼬인다는거~

    주의하시고 하면 됩니다.






  • Profile
    신철우 2006.08.23 00:23
    감사합니다.