How to convert old data from TRichEdit to TRichView
Posted: Wed Mar 06, 2024 10:58 am
Hi,
I have a huge database containing text (mix of Times New Roman and Symbol fonts). When I load one of these texts, I can see the style numbers. And when I load another text, I see same font names, but not with the same style number. In example : in the first text, I see that the style number 8 is Symbol in size 15, in the second the same style is now numbered 10.
My goal is to convert texts from this database in the same numbered styles, maybe 6 always Times New Roman size 14, 7 Symbol color navy, 8 Symbol color red, 9 Symbol color orange and 10 Symbol color green. As you can guess, text is composed with "normal text" and cards symbols (spade, heart, diamond and club).
I'm too newbie to get a good idea in coding that, and after many hours looking up for a way, reading hundred of this forum's items, I realize I need some help.
How I proceed :
I first load the text :
theBS := TABSBlobStream(TableDonnes.CreateBlobStream(FieldByName('COMMENT'), bmRead));
rve.Clear;
rve.LoadFromStream(theBS, rvynaAuto);
rve.Format;
theBS.Free;
Then I do :
rvs.ResetTextStyles;
rve.Format;
AjouteStyles;
rve.SelectAll;
rve.CurTextStyleNo := NormalStyle;
fd.Font.Assign(rvs.TextStyles[rve.CurTextStyleNo]);
rve.ApplyStyleConversion(TEXT_APPLYFONT);
rve.Deselect;
The procedure AjouteStyles :
var TextStyle: TFontInfo;
StyleNo: Integer;
begin
IgnoreChanges := True;
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
TextStyle.Color := clBlack;
TextStyle.BackColor := clInfoBk;
TextStyle.Size := 14;
TextStyle.FontName := 'Times New Roman';
TextStyle.StyleName := 'Normal Text';
rve.Style.TextStyles.Add;
StyleNo := rve.Style.TextStyles.Count - 1;
// CouleursStyles[pique] := StyleNo;
rve.Style.TextStyles[StyleNo].Assign(TextStyle);
rve.Style.TextStyles[StyleNo].Standard := False;
TextStyle.Free;
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
TextStyle.Color := clNavy;
TextStyle.BackColor := clInfoBk;
TextStyle.Size := 15;
TextStyle.FontName := 'Symbol';
TextStyle.StyleName := 'Pique';
rve.Style.TextStyles.Add;
StyleNo := rve.Style.TextStyles.Count - 1;
CouleursStyles[pique] := StyleNo;
rve.Style.TextStyles[StyleNo].Assign(TextStyle);
rve.Style.TextStyles[StyleNo].Standard := False;
TextStyle.Free;
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
TextStyle.Color := clRed;
TextStyle.BackColor := clInfoBk;
TextStyle.Size := 15;
TextStyle.FontName := 'Symbol';
TextStyle.StyleName := 'Coeur';
rve.Style.TextStyles.Add;
StyleNo := rve.Style.TextStyles.Count - 1;
CouleursStyles[coeur] := StyleNo;
rve.Style.TextStyles[StyleNo].Assign(TextStyle);
rve.Style.TextStyles[StyleNo].Standard := False;
TextStyle.Free;
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
TextStyle.Color := $0099FF;
TextStyle.BackColor := clInfoBk;
TextStyle.Size := 15;
TextStyle.FontName := 'Symbol';
TextStyle.StyleName := 'Carreau';
rve.Style.TextStyles.Add;
StyleNo := rve.Style.TextStyles.Count - 1;
CouleursStyles[carreau] := StyleNo;
rve.Style.TextStyles[StyleNo].Assign(TextStyle);
rve.Style.TextStyles[StyleNo].Standard := False;
TextStyle.Free;
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
TextStyle.Color := clGreen;
TextStyle.BackColor := clInfoBk;
TextStyle.Size := 15;
TextStyle.FontName := 'Symbol';
TextStyle.StyleName := 'Trefle';
rve.Style.TextStyles.Add;
StyleNo := rve.Style.TextStyles.Count - 1;
CouleursStyles[trefle] := StyleNo;
rve.Style.TextStyles[StyleNo].Assign(TextStyle);
rve.Style.TextStyles[StyleNo].Standard := False;
TextStyle.Free;
IgnoreChanges := False;
end;
As you can see, I get a text on good font and size (Times New Roman 14) but on bad BackColor (red and I want clInfoBk) because the style number is 11 and not 6 as I wanted it to be.
The styles from 6 to 10 are right, but what are these styles 11 and 12 ?
Thank you
I have a huge database containing text (mix of Times New Roman and Symbol fonts). When I load one of these texts, I can see the style numbers. And when I load another text, I see same font names, but not with the same style number. In example : in the first text, I see that the style number 8 is Symbol in size 15, in the second the same style is now numbered 10.
My goal is to convert texts from this database in the same numbered styles, maybe 6 always Times New Roman size 14, 7 Symbol color navy, 8 Symbol color red, 9 Symbol color orange and 10 Symbol color green. As you can guess, text is composed with "normal text" and cards symbols (spade, heart, diamond and club).
I'm too newbie to get a good idea in coding that, and after many hours looking up for a way, reading hundred of this forum's items, I realize I need some help.
How I proceed :
I first load the text :
theBS := TABSBlobStream(TableDonnes.CreateBlobStream(FieldByName('COMMENT'), bmRead));
rve.Clear;
rve.LoadFromStream(theBS, rvynaAuto);
rve.Format;
theBS.Free;
Then I do :
rvs.ResetTextStyles;
rve.Format;
AjouteStyles;
rve.SelectAll;
rve.CurTextStyleNo := NormalStyle;
fd.Font.Assign(rvs.TextStyles[rve.CurTextStyleNo]);
rve.ApplyStyleConversion(TEXT_APPLYFONT);
rve.Deselect;
The procedure AjouteStyles :
var TextStyle: TFontInfo;
StyleNo: Integer;
begin
IgnoreChanges := True;
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
TextStyle.Color := clBlack;
TextStyle.BackColor := clInfoBk;
TextStyle.Size := 14;
TextStyle.FontName := 'Times New Roman';
TextStyle.StyleName := 'Normal Text';
rve.Style.TextStyles.Add;
StyleNo := rve.Style.TextStyles.Count - 1;
// CouleursStyles[pique] := StyleNo;
rve.Style.TextStyles[StyleNo].Assign(TextStyle);
rve.Style.TextStyles[StyleNo].Standard := False;
TextStyle.Free;
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
TextStyle.Color := clNavy;
TextStyle.BackColor := clInfoBk;
TextStyle.Size := 15;
TextStyle.FontName := 'Symbol';
TextStyle.StyleName := 'Pique';
rve.Style.TextStyles.Add;
StyleNo := rve.Style.TextStyles.Count - 1;
CouleursStyles[pique] := StyleNo;
rve.Style.TextStyles[StyleNo].Assign(TextStyle);
rve.Style.TextStyles[StyleNo].Standard := False;
TextStyle.Free;
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
TextStyle.Color := clRed;
TextStyle.BackColor := clInfoBk;
TextStyle.Size := 15;
TextStyle.FontName := 'Symbol';
TextStyle.StyleName := 'Coeur';
rve.Style.TextStyles.Add;
StyleNo := rve.Style.TextStyles.Count - 1;
CouleursStyles[coeur] := StyleNo;
rve.Style.TextStyles[StyleNo].Assign(TextStyle);
rve.Style.TextStyles[StyleNo].Standard := False;
TextStyle.Free;
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
TextStyle.Color := $0099FF;
TextStyle.BackColor := clInfoBk;
TextStyle.Size := 15;
TextStyle.FontName := 'Symbol';
TextStyle.StyleName := 'Carreau';
rve.Style.TextStyles.Add;
StyleNo := rve.Style.TextStyles.Count - 1;
CouleursStyles[carreau] := StyleNo;
rve.Style.TextStyles[StyleNo].Assign(TextStyle);
rve.Style.TextStyles[StyleNo].Standard := False;
TextStyle.Free;
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
TextStyle.Color := clGreen;
TextStyle.BackColor := clInfoBk;
TextStyle.Size := 15;
TextStyle.FontName := 'Symbol';
TextStyle.StyleName := 'Trefle';
rve.Style.TextStyles.Add;
StyleNo := rve.Style.TextStyles.Count - 1;
CouleursStyles[trefle] := StyleNo;
rve.Style.TextStyles[StyleNo].Assign(TextStyle);
rve.Style.TextStyles[StyleNo].Standard := False;
TextStyle.Free;
IgnoreChanges := False;
end;
As you can see, I get a text on good font and size (Times New Roman 14) but on bad BackColor (red and I want clInfoBk) because the style number is 11 and not 6 as I wanted it to be.
The styles from 6 to 10 are right, but what are these styles 11 and 12 ?
Thank you