폰트의 색깔을 뿌려주고 다시 그 상태에서 다른 단어를 찾아 그 단어의 폰트 색깔을 바꾸려 하면
전에것도 색깔이 바뀌채로 그대로 있고 새단어도 바뀌는데
그이유가 뭘까요?
selattributes.color 의 값을 리셋 하고 싶은데 어떻게 하면되죠?
무척궁금합니다.
소스가 여기있습니다.
참고 해주세요.
------------------------------------------------------------------------------------------------------------------------
function TForm1.FindMemoStr(SrchStr: String; fromIndex: Integer; CaseSensitive: Boolean): Integer;
function Replichar(c: char; n: integer):string;
var
i: integer;
o: string;
begin
o := '';
for i := 1 to n do AppendStr(o,c);
Replichar := o;
end;
var
CRow, CCol, SRow, SCol: longint;
located: Boolean;
s, t, p: String;
linenum,colnum:word;
begin
Result :=0;
if length(SrchStr) < 1 then
System.Exit;
//richedit1의 주어진 위치부터 찾기위해
richedit1.SelStart := fromIndex;
located := False;
if CaseSensitive then
s := SrchStr
else
s := Uppercase(SrchStr);
with richedit1 do
begin
if richedit1.lines.count < 1 then
exit;
{현재 row and column을 얻는다}
CaretPos(RichEdit1.Handle,linenum,colnum);
CRow :=linenum ;
Ccol :=colnum;
SRow := CRow; {검색시작 row}
while (SRow < richedit1.lines.count) and not located do
begin
if CaseSensitive then
t := lines[SRow]
else
t := UpperCase(lines[SRow]);
if SRow = CRow then
begin
Delete(t,1,CCol+1);
p := Replichar(' ', CCol+1);
AppendStr(p, t);
t := p;
end;
SCol := pos(s, t);
if SCol > 0 then
begin
located := True;
end
else
inc(SRow);
end;
if located then
begin
SelStart := SendMessage(richedit1.Handle, EM_LineIndex, SRow, 0) + SCol - 1;
SelLength :=length(s);
setfocus;
selattributes.color:=clblue;
Result := SelStart;
end
else
begin
Result :=0;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
k:=0; // // 처음 찾기할 시작위치(SelStart)
Edit1.text :='this';
richedit1.Lines.loadfromfile('c:bible1.txt');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:= 1 to (richedit1.Lines.count) do
begin
k:= FindMemoStr(trim(Edit1.Text),k,CB_CaseSensitive.checked ); //accessviolation 0042F228 주의
if k = 0 then
begin
MessageBeep(MB_ICONHAND);
richedit1.SelAttributes.ConsistentAttributes ;
MessageDlg('더이상 찾는 문자열이 없습니다', mtInformation, [mbOK],0);
edit1.setfocus;
K:=0;
exit;
end;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
//FlashWindow(Form1.Handle, True);
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
//Timer1.Enabled := True;
end;
end.