Delphi 将richedit行中的前4个字符设为粗体

Delphi 将richedit行中的前4个字符设为粗体,delphi,richedit,Delphi,Richedit,如何将要加粗的行中的前4个字符变为粗体? 例如: 我想将Test设置为粗体,但将123设置为正常 有人能帮我吗?试试这样的方法: procedure TForm1.AddFormattedText(const AText: string; AStyle: TFontStyles); begin RichEdit1.SelStart := RichEdit1.GetTextLen; RichEdit1.SelLength := 0; RichEdit1.SelAttributes.St

如何将要加粗的行中的前4个字符变为粗体?
例如:

我想将
Test
设置为粗体,但将
123设置为正常


有人能帮我吗?

试试这样的方法:

procedure TForm1.AddFormattedText(const AText: string; AStyle: TFontStyles);
begin
  RichEdit1.SelStart := RichEdit1.GetTextLen;
  RichEdit1.SelLength := 0;
  RichEdit1.SelAttributes.Style := AStyle;
  RichEdit1.SelText := AText;
end;


虽然该问题并非完全重复,但该问题的第一个答案将为您提供所需的准确信息:
procedure TForm1.AddFormattedText(const AText: string; AStyle: TFontStyles);
begin
  RichEdit1.SelStart := RichEdit1.GetTextLen;
  RichEdit1.SelLength := 0;
  RichEdit1.SelAttributes.Style := AStyle;
  RichEdit1.SelText := AText;
end;
AddFormattedText('Test', [fsBold]);
AddFormattedText('123'+sLineBreak, []);