TRichEdit изменяем атрибуты
12.06.2026
функция для вывода текста с параметрами в конкретной строке TRichEdit

функция для вывода текста с параметрами в конкретной строке TRichEdit

void __fastcall TForm1::AppendColorTextToLine(TRichEdit* richEdit, int lineIndex, String textToAppend, TColor textColor, TFontStyles style, int FontS)
{
// 1. Safety check: Ensure the line exists
    if (lineIndex < 0 || lineIndex >= richEdit->Lines->Count) return;

    // 2. Get the character index of the start of the target line
//	int lineStartChar = SendMessage(richEdit->Handle, EM_LINEINDEX, lineIndex, 0);

	// 3. Calculate the position at the exact end of that line
// 	int lineEndChar = lineStartChar + richEdit->Lines->Strings[lineIndex].Length();
	int lineEndChar = richEdit->Lines->Strings[lineIndex].Length();

    // 4. Move the selection caret to the end of the line (selecting 0 characters)
    richEdit->SelStart = lineEndChar;
    richEdit->SelLength = 0;

    // 5. Apply the desired color to the upcoming selection
	richEdit->SelAttributes->Color = textColor;
	richEdit->SelAttributes->Style = style;
	richEdit->SelAttributes->Size = FontS;

	// 6. Insert the text
	richEdit->SelText = textToAppend;
}

пример вызова функции

		TFontStyles style;
		AppendColorTextToLine(YesNoForm1->Qestion, 0, " текст", clGreen, style << fsBold, 12);
		AppendColorTextToLine(YesNoForm1->Qestion, 0, " Убираем стиль Bold и меняем атрибуты ", clBlack, style >> fsBold, 10);