,delphi 232通讯,接收到的16进制数据,怎么转换成10进制,然后在edit.text中显示,edit.text是字符型?
procedureTFrmMain.Comm1ReceiveData(Sender:TObject;Buffer:Pointer;BufferLength:Word);v...
procedure TFrmMain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var str,Recstr: string;
begin
//Memo自动清空
if cbAutoClean.Checked and (Memo1.Lines.Count > 50) then
Memo1.Clear;
SetLength(str, BufferLength);
move(buffer^, pchar(@Str[1])^, bufferlength);
if FShowText then
begin
if cbRecHex.Checked then
Memo1.Text := Memo1.Text + StrToHexStr(str) + ' '
else
Memo1.Text := Memo1.Text + str;
Memo1.SelStart := Length(Memo1.Text);
Memo1.SelLength := 0;
Memo1.Perform(EM_SCROLLCARET, 0, 0);
edt44.Text:=StrToHexStr(str[14])+ StrToHexStr(str[13]);
end;
FRXNum := FRXNum + bufferlength;
ShowRX;
end;
procedure TFrmMain.ComboBox1Change(Sender: TObject);
begin
Comm1.CommName := ComboBox1.Text;
end;
这样接收显示下来的都是16进制的,怎么整改??? 展开
BufferLength: Word);
var str,Recstr: string;
begin
//Memo自动清空
if cbAutoClean.Checked and (Memo1.Lines.Count > 50) then
Memo1.Clear;
SetLength(str, BufferLength);
move(buffer^, pchar(@Str[1])^, bufferlength);
if FShowText then
begin
if cbRecHex.Checked then
Memo1.Text := Memo1.Text + StrToHexStr(str) + ' '
else
Memo1.Text := Memo1.Text + str;
Memo1.SelStart := Length(Memo1.Text);
Memo1.SelLength := 0;
Memo1.Perform(EM_SCROLLCARET, 0, 0);
edt44.Text:=StrToHexStr(str[14])+ StrToHexStr(str[13]);
end;
FRXNum := FRXNum + bufferlength;
ShowRX;
end;
procedure TFrmMain.ComboBox1Change(Sender: TObject);
begin
Comm1.CommName := ComboBox1.Text;
end;
这样接收显示下来的都是16进制的,怎么整改??? 展开
1个回答
展开全部
//如果十六进制非字符串, 无须转换, 直接赋值即可
var
i: Integer;
begin
i := $FF;
Edit1.Text:=(IntToStr(i));
end;
//如果十六进制是字符串, 用 StrToInt 即可
var
s: string;
i: Integer;
begin
s := '$FF';
i := StrToInt(s);
Edit1.Text:=(IntToStr(i));
end;
//如果你接收的数据里没有$, 加上就得了嘛
var
s: string;
i: Integer;
begin
s := 'FF';
i := '$'+StrToInt(s);
Edit1.Text:=(IntToStr(i));
end;
var
i: Integer;
begin
i := $FF;
Edit1.Text:=(IntToStr(i));
end;
//如果十六进制是字符串, 用 StrToInt 即可
var
s: string;
i: Integer;
begin
s := '$FF';
i := StrToInt(s);
Edit1.Text:=(IntToStr(i));
end;
//如果你接收的数据里没有$, 加上就得了嘛
var
s: string;
i: Integer;
begin
s := 'FF';
i := '$'+StrToInt(s);
Edit1.Text:=(IntToStr(i));
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询