只
只为美媚2
Unregistered / Unconfirmed
GUEST, unregistred user!
我从COM中接收到一个WideString的变量值,这个值是从串口接收到的数据.
WideString值型式为Chr($FF) + Chr($01) + Chr($02)...+ Chr($FF)
我要把它显示在界面上,以这样的形式 ‘FF,01,02...FF’
但当WideString 变量的值为Chr($F6)时,总是会出现问题代码如下(代码可以直接运行查看)
------------------------------------------------------------------------------
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm2 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
function GetDisPlayData(AHex: string): string;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TForm2 }
function TForm2.GetDisPlayData(AHex: string): string;
{*--
函数作用:如: Chr($01) +Chr($02) - > '01,02'
AHex:的格式 Chr($01) +Chr($02)
--*}
var
i,intCount,intValue:integer;
strResult:string;
begin
intCount := Length(AHex);
strResult := '';
for i := 1 To intCount Do
begin
intValue := Ord(AHex);
if i = intCount then
strResult := strResult + IntToHex(intValue,2)
else
strResult := strResult + IntToHex(intValue,2)+ ',';
end;//For
Result := strResult;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
{*--
函数的功能,将WideString字符串显示出来
--*}
var
ws:widestring;
s:string;
begin
ws:= Chr($F6);
if ws = Chr($F6) then
ShowMessage('ws = Chr($F6)')
//会显示
if ws[1] = Chr($F6) then
ShowMessage('ws[1] = Chr($F6)');//不显示
s := ws;//转化
if s = Chr($F6) then
ShowMessage('s = Chr($F6)');//不显示
if s[1] = Chr($F6) then
ShowMessage('s[1] = Chr($F6)');//不显示
showmessage(GetDisPlayData(s))
//会显示,但是错了, 显示为'00',我本意想为'F6'
{*-- 以下可以正常显示 --*}
s := Chr($F6);
showmessage(GetDisPlayData(s))
//显示正确
end;
end.
----------------
我的Email:175412977@QQ.com
WideString值型式为Chr($FF) + Chr($01) + Chr($02)...+ Chr($FF)
我要把它显示在界面上,以这样的形式 ‘FF,01,02...FF’
但当WideString 变量的值为Chr($F6)时,总是会出现问题代码如下(代码可以直接运行查看)
------------------------------------------------------------------------------
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm2 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
function GetDisPlayData(AHex: string): string;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TForm2 }
function TForm2.GetDisPlayData(AHex: string): string;
{*--
函数作用:如: Chr($01) +Chr($02) - > '01,02'
AHex:的格式 Chr($01) +Chr($02)
--*}
var
i,intCount,intValue:integer;
strResult:string;
begin
intCount := Length(AHex);
strResult := '';
for i := 1 To intCount Do
begin
intValue := Ord(AHex);
if i = intCount then
strResult := strResult + IntToHex(intValue,2)
else
strResult := strResult + IntToHex(intValue,2)+ ',';
end;//For
Result := strResult;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
{*--
函数的功能,将WideString字符串显示出来
--*}
var
ws:widestring;
s:string;
begin
ws:= Chr($F6);
if ws = Chr($F6) then
ShowMessage('ws = Chr($F6)')
//会显示
if ws[1] = Chr($F6) then
ShowMessage('ws[1] = Chr($F6)');//不显示
s := ws;//转化
if s = Chr($F6) then
ShowMessage('s = Chr($F6)');//不显示
if s[1] = Chr($F6) then
ShowMessage('s[1] = Chr($F6)');//不显示
showmessage(GetDisPlayData(s))
//会显示,但是错了, 显示为'00',我本意想为'F6'
{*-- 以下可以正常显示 --*}
s := Chr($F6);
showmessage(GetDisPlayData(s))
//显示正确
end;
end.
----------------
我的Email:175412977@QQ.com