我在memo控制元件中使用了如下代碼:
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
xs: PChar;
begin
GetLocalTime(st);
xs:=Buffer;
if(xs='1') then
xs:='退出1#油泵選擇!';
if(xs='a') then
xs:='選擇1#油泵!';
memo1.Lines.Add(xs+DateTimetostr(now()));
end;

為什么在運行的時候,時間會在memo控制元件上出現2次?謝謝!
uj5u.com熱心網友回復:
從代看,只顯示“退出1#油泵選擇!2017/8/28 7:16:49”后面的
2017/8/28 7:16:49
是不是激發事件的代碼中,有一條"memo1.Lines.Add(DateTimetostr(now())); 代碼。
"
uj5u.com熱心網友回復:
同意樓上,其他事件中應該還有add陳述句uj5u.com熱心網友回復:
沒有其它事件!uj5u.com熱心網友回復:
1、搜索全部的 memo1.Lines.Add欄位,看看是不是在什么地方觸發了事件。2、自己追蹤一下變數,看看這個時間是哪個變數賦值的。
uj5u.com熱心網友回復:
你的COM口接收資料處理有問題,你只對可見字符'1'和'a'做了處理,有可能是COM設備還回傳了其它內容,所以你的代碼中的xs:=Buffer,這樣處理是不完整的。
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
s:string;
i:Word;
p,pData:PByte;
begin
GetLocalTime(st);
s:='';
GetMem(pData,BufferLength);
Move(Buffer^, PByte(pData)^, BufferLength);
p:=pData;
i:=0;
s:='';
while i<BufferLength do
begin
s:=s+UpperCase(IntToHex(p^,2));
inc(p);
inc(i);
end;
memo1.Lines.Add(s+DateTimetostr(now()));//用16進制格式回傳接收到的資料
end;
uj5u.com熱心網友回復:
好,我試試!轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/50816.html
標籤:VCL組件開發及應用
