richedit 查詢 固定格式內的 文字,並改變 其顏色 或 加 超級連結
阿新 • • 發佈:2018-12-14
procedure SetRichEditStyle(vrich: TRichEdit); var startpos,FoundAt: Integer; cf2: CHARFORMAT2; begin startpos := 0; with vrich do begin FoundAt := FindText('【', startpos, Length(Text), []); while FoundAt <> -1 do begin SelStart := FoundAt; startpos := FoundAt + 1; FoundAt := FindText('】', startpos, Length(Text), []); if FoundAt <> -1 then begin SelLength := (FoundAt - selstart) + 1; SelAttributes.Style := []; SelAttributes.Color := clRed; {// ZeroMemory(@cf2, sizeof(CHARFORMAT2)); cf2.cbSize := sizeof(CHARFORMAT2); cf2.dwMask := CFM_LINK; cf2.dwEffects := CFE_LINK; redt1.Perform(EM_SETCHARFORMAT, SCF_SELECTION, integer(@cf2)); // } startpos := FoundAt + 1; FoundAt := FindText('【', startpos, Length(Text), []); end; end; end; end;