急啊!将下面的的C语言的代码转化为DELPHI中代码,如何实现? ( 积分: 100 )

  • 主题发起人 主题发起人 tanminr
  • 开始时间 开始时间
T

tanminr

Unregistered / Unconfirmed
GUEST, unregistred user!
将下面的的C语言的代码转化为DELPHI中的代码,如何实现?

USHORT checkcontent(USHORT *buffer, int size)
{

unsigned long ckct=0;
while(size >1)
{
ckct+=*buffer++;
size -=sizeof(USHORT);
}
if(size )
{
ckct += *(UCHAR*)buffer;
}
ckct = (ckct >> 16) + (ckct &amp
0xffff);
ckct += (ckct >>16);
return (USHORT)(~ckct);
}
 
将下面的的C语言的代码转化为DELPHI中的代码,如何实现?

USHORT checkcontent(USHORT *buffer, int size)
{

unsigned long ckct=0;
while(size >1)
{
ckct+=*buffer++;
size -=sizeof(USHORT);
}
if(size )
{
ckct += *(UCHAR*)buffer;
}
ckct = (ckct >> 16) + (ckct &amp
0xffff);
ckct += (ckct >>16);
return (USHORT)(~ckct);
}
 
function checkcontent(buffer : Pointer
size : Integer) : Word;
Var
ckct : Longword;
begin
ckct := 0;
while (size>1) do
begin
ckct := ckct + Word(buffer^);
size := size - sizeof(Word);
end;
if (size<>0) then ckct := ckct + Word(buffer^);
ckct := ( ckct shr 16 ) + (ckct And 65535);
ckct := ckct + ( ckct shr 16);
result := Word(Not ckct);
end;

procedure TForm1.Button1Click(Sender: TObject);
Var
w : Word;
begin
w := 100;
Edit1.Text := IntToStr(checkcontent(@w, 2));
end;
 
上面的写法有问题哦!!
看下面的写法:
type
TWordArray = array of Word;
function checkcontent(buffer : Pointer
size : Integer) : Word;
Var
ckct : Longword;
I : Integer;
buffer1 : TWordArray;
begin
buffer1 := TWordArray(buffer);
ckct := 0;
I := 0;
while (size>1) do
begin
ckct := ckct + buffer1;
Inc(I);
size := size - sizeof(Word);
end;
if (size<>0) then
ckct := ckct + buffer1;

ckct := ( ckct shr 16 ) + (ckct And $ffff);
ckct := ckct + ( ckct shr 16);
result := Word(Not ckct);
end;
 
接受答案了.
 

Similar threads

回复
0
查看
978
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部