1 pièce(s) jointe(s)
RichEdit et formatage de mot dans une ligne
Bonjour
Je ne voulais en arriver là mais j'en ai marre de tourner en rond.
Je cherche à écrire sur une ligne d'un TRichEdit des mots dans un format différent.
Le code que j'ai fait me parait bon et pourtant ça ne fonctionne et je ne comprends pas pourquoi.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
unit Unit8;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls;
type
TForm8 = class(TForm)
RichEdit1: TRichEdit;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
end;
var
Form8: TForm8;
implementation
{$R *.dfm}
type
TRichEditHelper = class helper for TRichEdit
procedure AddText(Texte: string; Styles: TFontStyles);
end;
var
Passage: Integer;
procedure Log(Texte: string);
begin
Form8.Memo1.Lines.Add(Texte);
end;
procedure TForm8.Button1Click(Sender: TObject);
begin
Passage := 0;
RichEdit1.AddText('Lundi', [fsBold]);
RichEdit1.AddText(' Mardi', [fsItalic]);
RichEdit1.AddText(' Mercredi', [fsUnderline]);
end;
{ TRichEditHelper }
procedure TRichEditHelper.AddText(Texte: string; Styles: TFontStyles);
begin
Inc(Passage);
Log(Format('Passage n° %d', [Passage]));
if Length(Lines.Text) = 0 then
begin
Text := Texte;
SelStart := 0;
end
else
begin
Lines[Pred(Lines.Count)] := Trim(Lines[Pred(Lines.Count)]) + Texte;
SelStart := Length(Lines.Text) - Texte.Length - 2;
end;
SelLength := Texte.Length;
Log(Format('SelStart = %d / SelLength = %d', [SelStart, SelLength]));
SelAttributes.Style := Styles;
SelStart := Texte.Length;
SelLength := 0;
SelAttributes.Style := [];
Refresh;
end;
end. |
Voilà le résultat :
Pièce jointe 656334
SelStart et SelLength semblent pourtant corrects et ça ne colle pas. :-(
Elle est où ma bêtise ?????