请高人把下面的代码转为delphi的代码,急用啊!非常感谢啊!!!本人对C一点都不懂啊...
{
int handle;
if(!(RadioButton_EditWhite->Checked || RadioButton_EditBlack->Checked))
return;
String stra = MaskEdit_WriteID->Text;
BYTE *pchara= stra.c_str();
BYTE x=pchara[0]-'0';
BYTE y =pchara[1]-'0';
x=x*10 + y;
if(x>42)
{
MaskEdit_WriteID->Text = "0000000000";
return;
}
UINT nTmp = StrToInt64(MaskEdit_WriteID->Text);
BYTE ByteTmp[10];
int j;
for(j=0; j<10; j++)
{
ByteTmp[j] = nTmp/GetMyByte(10, 9-j);
nTmp = nTmp%GetMyByte(10, 9-j);
}
for(j=0; j<5; j++)
ByteTmp[j] = (ByteTmp[j*2]<<4)|(ByteTmp[j*2+1]& 0x0f);
handle = open(strWriteFileDir.c_str(), O_CREAT |O_APPEND|O_RDWR |O_BINARY , S_IWRITE|S_IREAD);
if (handle == -1)
{
Label100->Caption = "Have Error!";
}
else
{
if(filelength(handle)==0L)
{
BYTE ch;
if(RadioButton_EditWhite->Checked)
{
ch = 0xaa;
write(handle, &ch, 1);
}
if(RadioButton_EditBlack->Checked)
{
ch = 0xbb;
write(handle, &ch, 1);
}
} Label100->Caption = "Is Writing...";
if(write(handle, ByteTmp, 5)==-1)
{
if(errno==EACCES )
Label100->Caption = "Permission denied";
else if(errno==EBADF)
Label100->Caption=" Bad file number";
else
Label100->Caption=" Write file error!" ;
}
else
Label100->Caption = "Have Writed!";
close(handle);
}
}
{
int handle;
if(!(RadioButton_EditWhite->Checked || RadioButton_EditBlack->Checked))
return;
String stra = MaskEdit_WriteID->Text;
BYTE *pchara= stra.c_str();
BYTE x=pchara[0]-'0';
BYTE y =pchara[1]-'0';
x=x*10 + y;
if(x>42)
{
MaskEdit_WriteID->Text = "0000000000";
return;
}
UINT nTmp = StrToInt64(MaskEdit_WriteID->Text);
BYTE ByteTmp[10];
int j;
for(j=0; j<10; j++)
{
ByteTmp[j] = nTmp/GetMyByte(10, 9-j);
nTmp = nTmp%GetMyByte(10, 9-j);
}
for(j=0; j<5; j++)
ByteTmp[j] = (ByteTmp[j*2]<<4)|(ByteTmp[j*2+1]& 0x0f);
handle = open(strWriteFileDir.c_str(), O_CREAT |O_APPEND|O_RDWR |O_BINARY , S_IWRITE|S_IREAD);
if (handle == -1)
{
Label100->Caption = "Have Error!";
}
else
{
if(filelength(handle)==0L)
{
BYTE ch;
if(RadioButton_EditWhite->Checked)
{
ch = 0xaa;
write(handle, &ch, 1);
}
if(RadioButton_EditBlack->Checked)
{
ch = 0xbb;
write(handle, &ch, 1);
}
} Label100->Caption = "Is Writing...";
if(write(handle, ByteTmp, 5)==-1)
{
if(errno==EACCES )
Label100->Caption = "Permission denied";
else if(errno==EBADF)
Label100->Caption=" Bad file number";
else
Label100->Caption=" Write file error!" ;
}
else
Label100->Caption = "Have Writed!";
close(handle);
}
}
Handle,j:Integer;
Stra:string;
PChara:PChar;
x,y,ch:Byte;
nTmp:UINT;
ByteTmp:array[0..9] of Byte;
begin
if(not(RadioButton_EditWhite.Checked or RadioButton_EditBlack.Checked))
Exit;
Stra := MaskEdit_WriteID.Text;
pchara := PChar(stra);
x := Byte(pchara[0])-Byte('0');
y :=Byte(pchara[1])-Byte('0');
x:=x*10 + y;
if(x> 42) then
begin
MaskEdit_WriteID.Text := '0000000000';
Exit;
end;
nTmp := StrToInt64(MaskEdit_WriteID.Text);
for j:=0 to 9 do
begin
ByteTmp[j] := nTmp/GetMyByte(10, 9-j);
nTmp := nTmp mod GetMyByte(10, 9-j);
end;
for j:=0 to 4 do
ByteTmp[j] := (ByteTmp[j*2] shl 4) or(ByteTmp[j*2+1]and $0f);
handle := open(PChar(strWriteFileDir), O_CREAT or O_APPEND or O_RDWR or O_BINARY , S_IWRITE or S_IREAD);
if (handle = -1) then
begin
Label100.Caption := 'Have Error!';
end
else
begin
if(filelength(handle)=0) then
begin if(RadioButton_EditWhite.Checked)then
begin
ch := $aa;
write(handle, @ch, 1);
end
if(RadioButton_EditBlack.Checked) then
begin
ch := $bb;
write(handle, @ch, 1);
end;
end; Label100.Caption := 'Is Writing...';
if(write(handle, ByteTmp, 5)=-1) then
begin
if(errno=EACCES ) then
Label100.Caption := 'Permission denied';
else if(errno=EBADF) then
Label100.Caption:=' Bad file number';
else
Label100.Caption:=' Write file error!' ;
end
else
Label100.Caption := 'Have Writed!';
close(handle);
end;
end;
var
stra: string;
x, y, ch: Byte;
ByteTmp: array[0..9] of Byte;
nTmp: LongWord;
j: Integer;
S: TStream;
begin
if not (RadioButton_EditWhite.Checked or RadioButton_EditBlack.Checked) then
Exit;
stra := MaskEdit_WriteID.Text;
x := Ord(stra[1]);
y := Ord(stra[2]);
x := x * 10 + y;
if x > 42 then
begin
MaskEdit_WriteID.Text := '0000000000';
Exit;
end;
nTmp := StrToInt64(MaskEdit_WriteID.Text);
for j := 0 to 9 do
begin
ByteTmp[j] := nTmp div GetMyByte(10, 9 - j);
nTmp := nTmp mod GetMyByte(10, 9 - j);
end;
for j := 0 to 4 do
ByteTmp[j] := (ByteTmp[j * 2] shl 4) or (ByteTmp[j * 2 + 1] and $0f);
S := TFileStream.Create(strWriteFileDir, fmOpenReadWrite);
try
try
if S.Size = 0 then
begin
if RadioButton_EditWhite.Checked then
begin
ch := $aa;
S.Write(ch, 1);
end;
if RadioButton_EditBlack.Checked then
begin
ch := $bb;
S.Write(ch, 1);
end;
Label100.Caption := 'Is Writing...';
S.Write(ByteTmp, 5);
end;
finally
S.Free;
end;
except
on EStreamError do
Label100.Caption := EStreamError.Message;
end;
end;
var
stra: string;
x, y, ch: Byte;
ByteTmp: array[0..9] of Byte;
nTmp: LongWord;
j: Integer;
S: TStream;
begin
if not (RadioButton_EditWhite.Checked or RadioButton_EditBlack.Checked) then
Exit;
stra := MaskEdit_WriteID.Text;
x := Ord(stra[1]);
y := Ord(stra[2]);
x := x * 10 + y;
if x > 42 then
begin
MaskEdit_WriteID.Text := '0000000000';
Exit;
end;
nTmp := StrToInt64(MaskEdit_WriteID.Text);
for j := 0 to 9 do
begin
ByteTmp[j] := nTmp div GetMyByte(10, 9 - j);
nTmp := nTmp mod GetMyByte(10, 9 - j);
end;
for j := 0 to 4 do
ByteTmp[j] := (ByteTmp[j * 2] shl 4) or (ByteTmp[j * 2 + 1] and $0f);
try
S := TFileStream.Create(strWriteFileDir, fmOpenReadWrite);
try
try
if S.Size = 0 then
begin
if RadioButton_EditWhite.Checked then
begin
ch := $aa;
S.Write(ch, 1);
end;
if RadioButton_EditBlack.Checked then
begin
ch := $bb;
S.Write(ch, 1);
end;
Label100.Caption := 'Is Writing...';
S.Write(ByteTmp, 5);
end;
finally
S.Free;
end;
except
on e: EStreamError do
Label100.Caption := e.Message;
end;
except
Label100.Caption := 'Have Error!';
end;
DWORD __fastcall TForm_PRCVersion::GetMyByte(BYTE m, BYTE n)
{
DWORD dwTmp;
dwTmp = 1;
for(BYTE i=0; i<n; i++)
dwTmp = dwTmp * m;
return dwTmp;
}
var
dwTmp:DWORD;
i:Byte;
begin
dwTmp := 1;
for i:=0 to n-1 do
dwTmp := dwTmp * m;
Result:= dwTmp;
end;