2009年4月1日 星期三

字元處理轉成文字 Char to Hex byte


procedure TFVoltage.com7ReceiveData(Sender: TObject; DataPtr:
Pointer; DataSize: Cardinal);
var s : string;
i : smallint;
begin
Label1.Caption := '';
s := stringofchar(' ',DataSize);
move(dataptr^,pchar(s)^,DataSize);
for i := 0 to DataSize-1 do
begin
if (s[i]<>'') and (i>3) and (i<(DataSize-2)) then
Label1.Caption := Label1.Caption+ '[' +inttostr(strtoint('0x' +
inttohex(byte(s[i]),2)))+ '] '
else if (byte(s[i])=0) and (i>3) and (i<(DataSize-2)) then
Label1.Caption := Label1.Caption+ '[' + '0' + '] ';
end;
ListBox1.Items.Insert(0,Label1.Caption);
end;