Delphi Syntax-Highlighting yapımı

DarkDesert

Kıdemli Üye
17 Eki 2011
2,043
1
TurkHackTeam
delphide kendi kod renklendirmenizi oluşturmak istemezmisiniz..aşağıdaki kaynak kodları inceleyerek kendi renk sisteminizi oluşturabilirsiniz.ister editor yapın ister başka bişi tamamen size kalmış

ekran görüntüsü
http://www.delphifr.com/gdi/c/53319.cs.jpg

unit U_Color;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;

type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Btn_Colorier: TButton;
procedure Btn_ColorierClick(Sender: TObject);
private
{ Dйclarations privйes }
public
{ Dйclarations publiques }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure HightLight_Syntax(ARE : TRichEdit);
//{$REGION ’Sub-functions’}
// Sous fonction seulement visible а l’intйrieur de HighLight_Syntax et qui a accиs а ARE
procedure HighLight_Others(AStart, AEnd : String; AColor : TColor);
var
iNext, iPos, iPos_End : Integer;
begin
iNext := 0;
iPos := ARE.FindText(AStart, iNext, Length(ARE.Text), [stMatchCase]);
while iPos <> -1 do // FindText renvoit -1 si il n’a pas trouvй AStart dans le RichEdit
begin
iNext := iPos + Length(AStart); // On rйtrйcit le texte а parcourir pour ne pas boucler sur toujours le mкme mot
ARE.SelStart := iPos; // On initialise la position de dйpart du RichEdit
iPos_End := ARE.FindText(AEnd, iNext, Length(ARE.Text), [stMatchCase]); // On cherche la position du deuxiиme caractиre qui doit arrкter la coloration
if iPos_End = -1 then
if AStart = ’’’’ then
iPos_End := ARE.FindText(#13, iNext, Length(ARE.Text), [stMatchCase]) // Quand il s’agit d’une ouverture de chaine (’), on termine la coloration а la fin de la ligne
else
iPos_End := Length(ARE.Text); // Par dйfaut, s’il manque le caractиre de fin, on termine la coloration а la fin du texte

ARE.SelLength := (iPos_End - iPos) + Length(AEnd); // On dйfinit jusqu’а oщ doit кtre colorй le texte
ARE.SelAttributes.Color := AColor; // Et on colore
if AStart = ’’’’ then
iPos := ARE.FindText(’’’’, iNext + iPos_End, Length(ARE.Text), [stMatchCase]) // Quand il s’agit d’une ouverture de chaine, la position de la chaine suivante doit commencer aprиs la fermeture de la derniиre chaine
else
iPos := ARE.FindText(AStart, iNext, Length(ARE.Text), [stMatchCase]);
end;
end;
//{$ENDREGION}

var
SL_Key_Word : TStringList;
i, iPos, iNext, iPos_Symb_Start, iPos_Symb_End, iTest : Integer;
const
C_Path = ’KeyWords.txt’;
begin
ARE.SelectAll;
ARE.SelAttributes.Color := clBlack;
SL_Key_Word := TStringList.Create;
try
SL_Key_Word.LoadFromFile(C_Path);
i := 0;
while i < SL_Key_Word.Count do
begin
iNext := 0;
iPos := ARE.FindText(SL_Key_Word, iNext, Length(ARE.Text), [stWholeWord]); // On ne recherche que les mots ENTIERS qui correspondent а un mot clef
while iPos <> -1 do
begin
iPos_Symb_Start := ARE.FindText(’_’, iPos - 1, 1, [stMatchCase]); // Pour йviter que les mots prйcйdйs de "_" ne soient colorйs aussi (FindText ne gиre pas зa)
if iPos = 0 then
iTest := 0 // Si la position est йgale а 0, c’est qu’il n’y a obligatoirement aucun "_" avant. Pour йviter que iPos - iPos_Symb_Start = 1.
else
iTest := iPos - iPos_Symb_Start;

iPos_Symb_End := ARE.FindText(’_’, iPos, Length(SL_Key_Word) + 1, [stMatchCase]); // Pour йviter que les mots suivis de "_" ne soient colorйs aussi
if (iTest <> 1) and (((Length(SL_Key_Word) + iPos) - iPos_Symb_End) + 1 <> 1) then // Si le mot n’est pas entourй de "_"
begin
iNext := iPos + Length(SL_Key_Word); // La prochaine recherche se fait а partir de la fin du dernier mot clef trouvй
ARE.SelStart := iPos;
ARE.SelLength := Length(SL_Key_Word);
ARE.SelAttributes.Color := clNavy;
end
else
iNext := iPos + Length(SL_Key_Word) - 1; // Ici ce n’est pas un mot clef

iPos := ARE.FindText(SL_Key_Word, iNext, Length(ARE.Text), [stWholeWord]); // Recherche du prochain mot clef
end;
inc(i);
end;

HighLight_Others(’(*’, ’*)’, clGreen);
HighLight_Others(’//’, #13, clGreen); // #13 reprйsente le saut de ligne
HighLight_Others(’{’, ’}’, clGreen);
HighLight_Others(’{$’, ’}’, clTeal);
HighLight_Others(’’’’, ’’’’, clBlue);
finally
SL_Key_Word.Free;
end;
end;

procedure TForm1.Btn_ColorierClick(Sender: TObject);
begin
HightLight_Syntax(RichEdit1);
end;

end.




Proje Download
https://rapidshare.com/files/2884466411/Syntax_highlighting_Delphi.rar
 
Üst

Turkhackteam.org internet sitesi 5651 sayılı kanun’un 2. maddesinin 1. fıkrasının m) bendi ile aynı kanunun 5. maddesi kapsamında "Yer Sağlayıcı" konumundadır. İçerikler ön onay olmaksızın tamamen kullanıcılar tarafından oluşturulmaktadır. Turkhackteam.org; Yer sağlayıcı olarak, kullanıcılar tarafından oluşturulan içeriği ya da hukuka aykırı paylaşımı kontrol etmekle ya da araştırmakla yükümlü değildir. Türkhackteam saldırı timleri Türk sitelerine hiçbir zararlı faaliyette bulunmaz. Türkhackteam üyelerinin yaptığı bireysel hack faaliyetlerinden Türkhackteam sorumlu değildir. Sitelerinize Türkhackteam ismi kullanılarak hack faaliyetinde bulunulursa, site-sunucu erişim loglarından bu faaliyeti gerçekleştiren ip adresini tespit edip diğer kanıtlarla birlikte savcılığa suç duyurusunda bulununuz.