var TramCptramecp :string; p:integer; begin p:= pos( chr($F8), trameCp); if p>0 then begin TrameCp := copy(TrameCp, 1, p-1) + chr($27) + copy(TrameCp, p+1, l-p); RichEdit1.lines[xxx] := TrameCp; end;
var TrameCp :string; p:integer; begin p:= pos( chr($F8), TrameCp); if p>0 then // si le caractère est présent on le remplace TrameCp[p] := chr($27); // dans tous les cas la trame est ajoutée RichEdit1.lines.Add(TrameCp); end;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionEt attention à l'unicode !Delphi le gère très bien et en toute transparence avec le code que j'ai donné ;-)
Et AnsiReplaceStr ne pourrait il pas être utilisé ?si mais AnsiReplaceStr utilise StringReplace qui se trouve être très lent et particulièrement gourmand en ressources
procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer); var NouveauMsg : string; PosEndTrame,i,p : Integer; begin {*** lecture du port com 1 ***} ComPort1.ReadStr(NouveauMsg, Count); MonMessage := MonMessage + NouveauMsg; MonMessage := Uppercase(MonMessage); PosEndTrame := Pos(#13, MonMessage); if PosEndTrame <> 0 then while PosEndTrame <> 0 do begin TrameCp := Copy(MonMessage, 0, PosEndTrame -1); //richEditRecept.Lines.Add(trameCp); // ecriture dans le RicheditRecept //Inc (Cpt_Evt); { *** Remplacement du caractère $F8 par $B0 ***} p := pos( chr($F8), TrameCp); if p>0 then TrameCp[p] := chr($B0); richEditRecept.Lines.Add(TrameCp); Inc (Cpt_Evt); { *** Mis en couleur de certaines lignes et écriture dans les RichEdit respectif *** } if (pos(' OPR ', TrameCP)) <> 0 then begin RichEdit_OPR.SelAttributes.Color := clBlue; RichEdit_OPR.Lines.Add(TrameCp); Inc (Cpt_Alm_Inhi); end; if (Pos(' ALM ', TrameCp)) <> 0 then begin RichEditLog.SelAttributes.Color := clred ; richEditLog.Lines.Add(TrameCp); Inc (Cpt_ALM); end; if (Pos(' ACK ', TrameCp)) <> 0 then begin //RichEditLog.SelAttributes.Color := $000080FF; // Orange RichEditLog.SelAttributes.Color := clTeal; richEditLog.Lines.Add(trameCp); end; if (Pos(' RTN ', TrameCp)) <> 0 then begin RichEditLog.SelAttributes.Color := clLime; RichEditLog.Lines.Add(trameCp); end; MonMessage := Copy(MonMessage, PosEndTrame +1, Length(MonMessage)); PosEndTrame := Pos(#13, MonMessage); end; end;