各位高人:
    我碰到这样一个问题:我有一个Pchar类型的值,如〔‘^’,#252,‘Q’,‘M’,#24,#228,。,#224,#0〕
    现在我想把这组数据转化为byte类型的array数组,该如何做?
    有人说,可以先转化成PBYTEARRAY,但是pchar如何转成Pbytearray呢?
    先谢谢各位!

解决方案 »

  1.   

    不转不行吗?
    我一向是用String存储byteArray的.
    使用时只要byte(PChar[Index])就可以了
      

  2.   

    为什么一定要把PChar类型转换为Byte类型的数组呢?为什么一定要在Pascal语言中使用C语言的特性呢?既然是使用Pascal,就应当使用Pascal的特性,否则是自找麻烦!
    var
      byteArray: array of Byte;
      pCh: PChar;
      i: Integer;
      s: string;
    begin
      pCh := PChar('ABCD');
      SetLength(byteArray, StrLen(pCh));
      for i := 0 to StrLen(pCh) do
      begin
        byteArray[i] := Byte((pch + i)^);
        s := s + Char(byteArray[i]);
      end;
      ShowMessage(s);
    end;如果使用string:
    s := StrPas(pCh);           // 看,多简单!
    如果要单个字符,则只要以数组形式看呆string类型就可以了:
    s[1] 为 'A';  s[2] 为 'B'; s[3] 为 'C';  s[4] 为 'D';
      

  3.   

    为什么一定要把PChar类型转换为Byte类型的数组呢?为什么一定要在Pascal语言中使用C语言的特性呢?既然是使用Pascal,就应当使用Pascal的特性,否则是自找麻烦!
    var
      byteArray: array of Byte;
      pCh: PChar;
      i: Integer;
      s: string;
    begin
      pCh := PChar('ABCD');
      SetLength(byteArray, StrLen(pCh));
      for i := 0 to StrLen(pCh) do
      begin
        byteArray[i] := Byte((pch + i)^);
        s := s + Char(byteArray[i]);
      end;
      ShowMessage(s);
    end;如果使用string:
    s := StrPas(pCh);           // 看,多简单!
    如果要单个字符,则只要以数组形式看呆string类型就可以了:
    s[1] 为 'A';  s[2] 为 'B'; s[3] 为 'C';  s[4] 为 'D';
      

  4.   

    var
      C : Pchar;
      B : Array [0..7] of Byte;
      iLen : Integer;
    begin
      iLen := SizeOf(B);       // Get the lenth for allocat, clear, copy and compare.
      GetMem(C,iLen);          // Set Pchar Length.
      ZeroMemory(C,iLen);      // Zero Pchar Memory.
      ZeroMemory(@b,iLen);     // Zero Byte array Memory.
      if CompareMem(c,@b,iLen) then showmessage('same');  // Compare.
      c := 'Hello#^' + #253;     // Set Pchar value.
      if CompareMem(c,@b,iLen) then showmessage('same'); // Compare.
      CopyMemory(@B,C,iLen);    // Copy pchar to byte.
      if CompareMem(c,@b,iLen) then showmessage('same');  // Compare.
      

  5.   

    var
      C : Pchar;
      B : Array [0..7] of Byte;
      iLen : Integer;
    begin
      iLen := SizeOf(B);       // Get the lenth for allocat, clear, copy and compare.
      GetMem(C,iLen);          // Set Pchar Length.
      ZeroMemory(C,iLen);      // Zero Pchar Memory.
      ZeroMemory(@b,iLen);     // Zero Byte array Memory.
      if CompareMem(c,@b,iLen) then showmessage('same');  // Compare.
      c := 'Hello#^' + #253;     // Set Pchar value.
      if CompareMem(c,@b,iLen) then showmessage('same'); // Compare.
      CopyMemory(@B,C,iLen);    // Copy pchar to byte.
      if CompareMem(c,@b,iLen) then showmessage('same');  // Compare.
      

  6.   

    var
      C : Pchar;
      B : Array [0..7] of Byte;
      iLen : Integer;
    begin
      iLen := SizeOf(B);       // Get the lenth for allocat, clear, copy and compare.
      GetMem(C,iLen);          // Set Pchar Length.
      ZeroMemory(C,iLen);      // Zero Pchar Memory.
      ZeroMemory(@b,iLen);     // Zero Byte array Memory.
      if CompareMem(c,@b,iLen) then showmessage('same');  // Compare.
      c := 'Hello#^' + #253;     // Set Pchar value.
      if CompareMem(c,@b,iLen) then showmessage('same'); // Compare.
      CopyMemory(@B,C,iLen);    // Copy pchar to byte.
      if CompareMem(c,@b,iLen) then showmessage('same');  // Compare.
    end;