To CoolSlob: 出错信息是: Access violation at address 000000135. Read of address 00000135To orent_c 函数可以这么调用的!
还有两个函数是: function upk_mac(x:Integer):Integer; begin Result:=(x or $30); end; function pk_mac(x:Integer):Integer; begin Result:=(x and $0F); end;
通过仔细阅读你的程序,我知道你的问题出在哪里了。 你的问题在于你的定义: function packing(p3:pchar;len:Integer;bitmap:PChar):Integer; 而你在调用程序里又要使用bitmap; 当然BITMAP不会出现你想要的值,因为你使用的只是值传递。
To mrzho PChar 是指针呀,相当域C中的char * ,不就是传地址了吗?你认为应该怎么做呢?
To liujc 运行的时候才出错的!编译不会错!
bitmap[8]:=#0;错了 改 procedure TForm1.Button1Click(Sender: TObject); var tmp:array[0..15] of char; bitmap:array[0..8] of char;//这里 x:string; i:Integer; begin StrPCopy(tmp,'01ff000000000000'); FillChar(bitmap,8,0); packing(tmp,16,bitmap); for i:=0 to 7 do x:=x+Format('%.2x',[ord(bitmap[i])]); ShowMessage(x); end;
错在这里: bitmap[8]:=#0; 改为:bitmap[7]:=#0;
bitmap:array[0..7] of char 改为 bitmap:array[0..8] of char
出错信息是:
Access violation at address 000000135. Read of address 00000135To orent_c
函数可以这么调用的!
function upk_mac(x:Integer):Integer;
begin
Result:=(x or $30);
end;
function pk_mac(x:Integer):Integer;
begin
Result:=(x and $0F);
end;
你的问题在于你的定义:
function packing(p3:pchar;len:Integer;bitmap:PChar):Integer;
而你在调用程序里又要使用bitmap;
当然BITMAP不会出现你想要的值,因为你使用的只是值传递。
PChar 是指针呀,相当域C中的char * ,不就是传地址了吗?你认为应该怎么做呢?
运行的时候才出错的!编译不会错!
改
procedure TForm1.Button1Click(Sender: TObject);
var
tmp:array[0..15] of char;
bitmap:array[0..8] of char;//这里
x:string;
i:Integer;
begin
StrPCopy(tmp,'01ff000000000000');
FillChar(bitmap,8,0);
packing(tmp,16,bitmap); for i:=0 to 7 do
x:=x+Format('%.2x',[ord(bitmap[i])]); ShowMessage(x);
end;
改为:bitmap[7]:=#0;
改为
bitmap:array[0..8] of char