object Form1: TForm1 Left = 220 Top = 155 Width = 497 Height = 397 Caption = 'Form1' Color = clBtnFace Font.Charset = SHIFTJIS_CHARSET Font.Color = clWindowText Font.Height = -12 Font.Name = 'MS Pゴシック' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 12 object RichEdit1: TRichEdit Left = 0 Top = 0 Width = 353 Height = 367 Align = alLeft HideScrollBars = False Lines.Strings = ( 'RichEdit1' 'unit SCFREdString;' '' 'interface' '' 'uses' ' Windows, Messages, SysUtils, Classes, Graphics, Controls, Form' + 's, Dialogs,' ' ComCtrls, RichEdit;' '' 'procedure SetCharFormatRichEdString( RichEdit: TRichEdit;' ' const SearchStr: String; StrColor: TColor; StrFStyle: TFontStyl' + 'es);' '' 'implementation' '' 'procedure SetCharFormatRichEdString( RichEdit: TRichEdit;' ' const SearchStr: String; StrColor: TColor; StrFStyle: TFontStyl' + 'es);' 'var' ' mask: Longint;' ' CFmt: TCharFormat;' ' Str: String;' ' PTop, PPos, PEnd, PSearch: PChar;' ' CR: TCharRange;' 'begin' ' with RichEdit do' ' try' ' Lines.BeginUpdate;' ' mask := SendMessage(Handle, EM_GETEVENTMASK, 0, 0);' ' SendMessage(Handle, EM_SETEVENTMASK, 0, 0);' '' ' SelStart := length(Text);' ' Perform(EM_SCROLLCARET, 0, 0);' '' '//−−−−−−−−−−−' ' CFmt.cbSize := sizeof(CFmt);' '' ' if ( StrColor <> 0 ) then' ' begin' ' CFmt.dwMask := CFM_COLOR;' ' CFmt.crTextColor := ColorToRGB(StrColor);' ' end;' '' ' if ( fsBold in StrFStyle ) then' ' begin' ' CFmt.dwMask := CFmt.dwMask or CFM_BOLD;' ' CFmt.dwEffects := CFmt.dwEffects or CFM_BOLD;' ' end;' ' if ( fsItalic in StrFStyle ) then' ' begin' ' CFmt.dwMask := CFmt.dwMask or CFM_ITALIC;' ' CFmt.dwEffects := CFmt.dwEffects or CFM_ITALIC;' ' end;' ' if ( fsUnderline in StrFStyle ) then' ' begin' ' CFmt.dwMask := CFmt.dwMask or CFM_UNDERLINE;' ' CFmt.dwEffects := CFmt.dwEffects or CFM_UNDERLINE;' ' end;' ' if ( fsStrikeOut in StrFStyle ) then' ' begin' ' CFmt.dwMask := CFmt.dwMask or CFM_STRIKEOUT;' ' CFmt.dwEffects := CFmt.dwEffects or CFM_STRIKEOUT;' ' end;' '' '' ' CFmt.dwMask := CFM_COLOR;' ' CFmt.crTextColor := ColorToRGB(StrColor);' '' '//−−−−−−−−−−−' '' ' Str := RichEdit.Text;' ' PTop := PChar(AnsiUpperCase(Str));' ' PPos := PTop; //すべて大文字にして、検索時大小文字の区別無' + 'し' '' ' PSearch := PChar(AnsiUpperCase(SearchStr));' ' //すべて大文字に' ' while (AnsiStrPos(PPos, PSearch) <> nil) do' ' begin' ' PPos := AnsiStrPos( PPos, PSearch ) ;' ' PEnd := PPos + ( Length(SearchStr) );' '' ' CR.cpMin := PPos - PTop;' ' CR.cpMax := PEnd - PTop;' ' Perform(EM_EXSETSEL, 0, lParam(@CR));' ' Perform(EM_SETCHARFORMAT, 1, lParam(@CFmt));//書式決定' ' PPos := PEnd;' ' end;' '' ' finally' ' SendMessage(Handle, EM_SETEVENTMASK, 0, mask);' ' Lines.EndUpdate;' ' end;' 'end;' '' '{' 'この部分' ' CFmt.cbSize := sizeof(CFmt);' ' CFmt.dwMask := CFM_COLOR;' ' CFmt.crTextColor := ColorToRGB(TagColor);' 'を' ' CFmt.cbSize := sizeof(CFmt);' ' CFmt.dwMask := CFM_BOLD;' ' CFmt.dwEffects := CFE_BOLD;' 'これに変えれば太文字になりますし' '' ' CFmt.cbSize := sizeof(CFmt);' ' CFmt.dwMask := CFM_COLOR or CFM_BOLD;' ' CFmt.dwEffects := CFE_BOLD;' ' CFmt.crTextColor := ColorToRGB(StrColor);' 'こうすると太字+色つきになります。' '}' '' 'end.') ScrollBars = ssBoth TabOrder = 0 WordWrap = False end object Button1: TButton Left = 368 Top = 24 Width = 89 Height = 33 Caption = 'Button1' TabOrder = 1 OnClick = Button1Click end end