تلوين البحث و التغيير Search And Replace
#5
- تعديل بسيط , أرجــوا أن يفيدك لست متأكد 100% :
PHP كود :
{$WARNINGS OFF} {$HINTS OFF}
{
$O ON}{$OverFlowChecks OFF}

Type
  CHARFORMAT 
= record
    cbSize
: UINT;
    
dwMask: DWORD;
    
dwEffects: DWORD;
    
yHeight: Longint;
    
yOffset: Longint;
    
crTextColor: TColorRef;
    
bCharSet: Byte;
    
bPitchAndFamily: Byte;
    
szFaceName: array[0..LF_FACESIZE - 1] of AnsiChar;
    
wWeight: Word;                   { Font weight (LOGFONT value)         }
    
sSpacing: Smallint;              { Amount to space between letters     }
    
crBackColor: TColorRef;          { Background color                     }
    
lid: LCID;                       { Locale ID                         }
    
dwReserved: DWORD;               { Reserved. Must be 0                 }
    
sStyle: Smallint;                { Style handle                         }
    
wKerning: Word;                  { Twip size above which to kern char pair }
    
bUnderlineType: Byte;            { Underline type                     }
    
bAnimation: Byte;                { Animated text like marching ants     }
    
bRevAuthor: Byte;                { Revision author index             }
    
bReserved1: Byte;
 
End;

Type
 TOrdArr 
= Array [0..500] Of Word; //500 Mush String & 65535 Max Ord !
Var
 
MyArr: TOrdArr;

Procedure GetOrdArr(_Text,sLookFor:String);
{
$IF CompilerVersion >= 17}Inline;{$IFEND}
Var
 
i: Word;
Begin
{Initialize Vars}
i:= 1; MyArr[0]:= 0;
While 
Pos(sLookFor, _Text) > 0 Do
Begin
 MyArr
[i]:=Pos(sLookFor, _Text) + MyArr[i-1];
 
_Text:=Copy(_Text,(Pos(sLookFor, _Text)+1),Length(_Text));
Inc(i);
End;
End;

Const
  
col: array[1..6] of Dword =($0000FF, $008000, $800000,
                              
$FF0000, $FFFF00, $00FF00);

Procedure SearchAndReplace_color(Richedit: TRichEdit; sLookFor, sReplaceWith:string; col: Dword);
          {
$IF CompilerVersion >= 17}Inline;{$IFEND}
Var
  
nPos : Integer;
  
i: Word;
Begin
nPos
:= Pos(sLookFor, Richedit.Text);
Richedit.Text  := Trim(StringReplace(Richedit.Text,
                                     
sLookFor     ,
                                     
sReplaceWith ,
                                     [
rfReplaceAll{,rfIgnoreCase}]));
GetOrdArr(Richedit.Text,sReplaceWith);
i:= 1;
 While (
MyArr[i] > 0) do
 
Begin
  With Richedit 
do
   
Begin
    SelStart 
:= MyArr[i]-1;
    
SelLength := Length(sReplaceWith);
    
SelAttributes.Color := col;
    
inc(i);
   
End;
 
End;
End;

procedure SetRichEditBgColor(RichEdit: TRichEdit; AColor: Dword);
                       {
$IF CompilerVersion >= 17}Inline;{$IFEND}
var
  
Format: CHARFORMAT;
begin
  FillChar
(Format, SizeOf(Format), 0);
  
with Format do
  
begin
    cbSize 
:= SizeOf(Format);
    
dwMask := $04000000;
    
crBackColor := AColor;
    
SendMessage(RichEdit.Handle,(WM_USER + 68), $0004,Longint(@Format)); //SCF_SELECTION=$0001  
 
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 SearchAndReplace_color
(redt1, 'SDK', 'xxx', Col[1]);
 
//SetRichEditBgColor(redt1, $FFFF00);
end; 
بالتوفيق,,
I'M Fly Like A G6

الرد


الردود في هذا الموضوع
تلوين البحث و التغيير Search And Replace - بواسطة TF6M - 19-05-2011, 12:55 AM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم