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可以编译通过,这是为什么啊......
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可以编译通过,这是为什么啊......
PChar是可以看做是字符串数组
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;procedure TForm15.btn1Click(Sender: TObject);
var
dest : array[0..2] of Byte;
begin
dest[0] := 4;
dest[1] := 5;
dest[2] := 6;
bb([1, 2, 3], dest, 0, 3); //返回 dest{1, 2, 3}end;
编译不通过啊,
[Error] Unit1.pas(35): Array type required
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;
你要么使用数组指针, 要么就数组, 两个来回绕弯是给你自己使绊子你的功能可以简化成这样
Procedure bb(const Source: Array of Byte; var Dest: Array of Byte; Idx, count : Integer);
var
I: Integer;
begin
for I := 0 to count-1 do
Dest[I+Idx] := Source[I];
end;
而PByte = ^Byte; 那么PByte就是指向Byte的指针,范围就是0..255的数值了