sisi231
Messages postés207Date d'inscriptionmercredi 5 mars 2003StatutMembreDernière intervention29 mars 2013
-
7 mai 2006 à 19:46
sisi231
Messages postés207Date d'inscriptionmercredi 5 mars 2003StatutMembreDernière intervention29 mars 2013
-
8 mai 2006 à 14:10
Bonjour !
Je voudrais savoir comment récupérer le caractère juste avant le caret et celui juste après d'un TRichEdit !...
J'ai essayé ainsi :
with richedit1 do
begin
sellength:=0;// pour forcer l'apparition du caret
car_vant:=text[selstart-1];
car_apres:=text[selstart+1];
end;
mais ni car_avnt ni car_apres ne sont bons, ils sont même très loin de la
réalité.
Je pense que le problème est dû aux caractères #13#10...
NB : J'ai essayé aussi avec lines.text mais c'est pareil.
f0xi
Messages postés4205Date d'inscriptionsamedi 16 octobre 2004StatutModérateurDernière intervention12 mars 202235 8 mai 2006 à 00:37
alors ce fut assé chaud de trouver mais voila a peu prés ce que cela peu donner :
function _InRange(V,AMin,AMax : integer) : integer;
begin
if V < AMin then
result := AMin
else
if V > AMax then
result := AMax
else
result := V;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
S : string;
PS,PL : PChar;
SL,X,Y : integer;
PC,CC,NC : string;
CPos : integer;
begin
SL := 0;
{ on compte le nombre total de caracteres visible }
for X := 0 to RichEdit1.Lines.Count-1 do begin
SL := SL + Length(RichEdit1.Lines[X]);
end;
{ on init S a la longeur totale calculée }
SetLength(S,SL);
{ on Pcharize S }
PS := PChar(S);
{ on place tout le texte dans S, attention cela pourrait etre long si beaucoup de texte }
for X := 0 to RichEdit1.Lines.Count-1 do begin
PL := PChar(RichEdit1.Lines[X]);
while PL[0] <> #0 do begin
PS[0] := PL[0];
inc(PS);
inc(PL);
end;
end;
{ on termine S par le 0 ... chaine AZT oblige }
PS[0] := #0;
{ on reinit SL }
SL := 0;
{ on calcul la position par rapport a Y et X }
if RichEdit1.CaretPos.Y > 0 then
for X := 0 to RichEdit1.CaretPos.Y-1 do
SL := SL + Length(RichEdit1.Lines[X]);
CPos := SL + (RichEdit1.CaretPos.X + 1);
{ si on trouve des caracteres, on affiche ces derniers en hexa }
if _InRange(CPos,1,Length(S)) then
CC := format('$%.2x',[ord(S[CPos])])
else
CC := '(aucun)';
if _InRange(CPos-1,1,Length(S)) then
PC := format('$%.2x',[ord(S[CPos-1])])
else
PC := '(aucun)';
if _InRange(CPos+1,1,Length(S)) then
NC := format('$%.2x',[ord(S[CPos+1])])
else
NC := '(aucun)';
{ on reinit S a 0 }
SetLength(S,0);
{ on affiche le resultat dans label1 }
label1.Caption := format('precedent : %s, courrant : %s, suivant : %s',[PC,CC,NC]);
end;
bien entendus ce n'est valide que pour la ligne en cours ...
il ne prend pas la ligne precedente ni suivante en cours ... mais tu pourras facilement l'adapter pour qu'il le prenne en compte.