chotib 0 Newbie Poster

i am confused about syntax highlighting, if i am paste text from clipboard to RichEdit, the syntax highlighling doesnt work perfectly.

here is my code :

//On header(FWDesign.h) define
TStringList *htmltag;
TStringList *atribut;

//On FormCreate
void __fastcall TFWDesign::FormCreate(TObject *Sender)
{
	htmltag = new (TStringList);
	atribut = new (TStringList);

	htmltag->Add("html");
	htmltag->Add("body");
	htmltag->Add("h1");
	htmltag->Add("h2");
	htmltag->Add("h3");
	htmltag->Add("h4");
	htmltag->Add("h5");
	htmltag->Add("h6");
	htmltag->Add("p");
	htmltag->Add("br");
	htmltag->Add("hr");
	htmltag->Add("b");
	htmltag->Add("big");
	htmltag->Add("blockquote");
	htmltag->Add("center");
	htmltag->Add("code");
	htmltag->Add("font");
	htmltag->Add("i");
	htmltag->Add("pre");
	htmltag->Add("s");
	htmltag->Add("small");
	htmltag->Add("strike");
	htmltag->Add("strong");
	htmltag->Add("u");
	htmltag->Add("Address");
	htmltag->Add("form");
	htmltag->Add("input");
	htmltag->Add("textarea");
	htmltag->Add("button");
	htmltag->Add("select");
	htmltag->Add("option");
	htmltag->Add("frame");
	htmltag->Add("frameset");
	htmltag->Add("iframe");
	htmltag->Add("img");
	htmltag->Add("map");
	htmltag->Add("a");
	htmltag->Add("link");
	htmltag->Add("ul");
	htmltag->Add("ol");
	htmltag->Add("li");
	htmltag->Add("table");
	htmltag->Add("th");
	htmltag->Add("tr");
	htmltag->Add("td");
	htmltag->Add("style");
	htmltag->Add("div");
	htmltag->Add("span");
	htmltag->Add("head");
	htmltag->Add("title");
	htmltag->Add("meta");
	htmltag->Add("script");
	htmltag->Add("marquee");

	atribut->Add("align");
	atribut->Add("valign");
	atribut->Add("width");
	atribut->Add("height");
	atribut->Add("border");
	atribut->Add("bgcolor");
	atribut->Add("background");
	atribut->Add("cellpadding");
	atribut->Add("cellspacing");
	atribut->Add("href");
	atribut->Add("src");
	atribut->Add("target");
	atribut->Add("rowspan");
	atribut->Add("colspan");
	atribut->Add("type");
	atribut->Add("rows");
	atribut->Add("cols");
	atribut->Add("method");
	atribut->Add("action");
	atribut->Add("name");
	atribut->Add("value");
	atribut->Add("language");
	atribut->Add("id");
	atribut->Add("class");
	atribut->Add("alt");
	atribut->Add("rel");
	atribut->Add("content");
	atribut->Add("http-equiv");
	atribut->Add("charset");
	atribut->Add("face");
	atribut->Add("color");
	atribut->Add("size");
}

//on RichEdit Change
void __fastcall TFWDesign::RichEdit1Change(TObject *Sender)
{
	::SendMessage(RichEdit1->Handle, WM_SETREDRAW, false, 0);//disable richedit
	if ( RichEdit1->Modified )
	{
		int pawal;
		AnsiString teks;

		pawal = RichEdit1->SelStart;

		RichEdit1->SelStart = ::SendMessage( RichEdit1->Handle,EM_FINDWORDBREAK,
										 WB_MOVEWORDLEFT,pawal );

		RichEdit1->SelLength = ::SendMessage( RichEdit1->Handle,EM_FINDWORDBREAK,
										  WB_MOVEWORDRIGHT,RichEdit1->SelStart ) -
										  RichEdit1->SelStart ;

		teks = RichEdit1->SelText;

		teks = teks.TrimLeft();
		teks = teks.TrimRight();
		
		for(int i=0;i<htmltag->Count;i++)
		{
			if (teks==htmltag->Strings[i])
			{
				RichEdit1->SelAttributes->Color=clBlue;
			}
		}
		
		for(int i=0;i<atribut->Count;i++)
		{
			if (teks==atribut->Strings[i])
			{
				RichEdit1->SelAttributes->Color=clRed;
			}
		}
		RichEdit1->SelStart=pawal;
		RichEdit1->SelAttributes->Color=clBlack;
	}

	::SendMessage(RichEdit1->Handle, WM_SETREDRAW, true, 0);//enable richedit
	::InvalidateRect(RichEdit1->Handle, 0, true);//setfocus richedit

}

thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.