首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

PChar与PByte 有什么区别?该怎么解决

2013-04-26 
PChar与PByte 有什么区别?Procedure aa(const Source: Array of Byte var Dest: Array of Byte Idx, cou

PChar与PByte 有什么区别?
Procedure aa(const Source: Array of Byte; var Dest: Array of Byte; Idx, count : Integer);
var
    S, D: PChar;
    II : Integer ;
begin
    S := PChar(@ResArray);
    D := PChar(@DesArray);
    for II := 0 to CCount -1 do
    begin
        D[II] :=  S[BIdx + II]
    end;
end;

Procedure bb(const Source: Array of Byte; var Dest: Array of Byte; Idx, count : Integer);
var
  S, D: PByte;
  I: Integer;
begin
  S := PByte(@Source);
  D := PByte(@Dest);
 for I := 0 to count-1 do
      D[I+Idx] := S[I];
end;


在使用Pbyte的时候要求类型,编译不通过,Pchar可以编译通过,这是为什么啊......
[解决办法]
看不懂你的问题和代码,而且这两个函数乱七八糟,N个变量都没定义。
[解决办法]
因为PByte是指向一个Byte类型的指针,只占一个字节
PChar是可以看做是字符串数组
[解决办法]
  如果你一定要使用PByte你就这样写吧! 

var
  S, D: PByte;
  I: Integer;
begin
  S := PByte(@Source);
  D := PByte(@Dest);
 for I := 0 to count-1 do
      PByte(integer(D)+ I + Idx)^ := PByte(integer(S) + I)^;
end;
[解决办法]

或者下面的代码也可以!
var
  S, D: PByteArray;
  I: Integer;
begin
  S := PByteArray(@Source);
  D := PByteArray(@Dest);
 for I := 0 to count-1 do
      D[I + Idx] := S[I];
end;

热点排行