-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit1.cpp
More file actions
77 lines (73 loc) · 1.98 KB
/
Unit1.cpp
File metadata and controls
77 lines (73 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "hash_class.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
hash_table tbl(25000);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Memo1->Lines->LoadFromFile("..\\..\\EN_Word_25.txt");
for (int i=0; i<Memo1->Lines->Count; i++) {
tbl.insert(Memo1->Lines->Strings[i],Memo1->Lines->Strings[i]);
}
}
void __fastcall TForm1::Highlight()
{
CHARFORMAT2 CF;
CF.cbSize=sizeof(CF);
CF.dwMask=CFM_BACKCOLOR;
CF.dwEffects=CFE_PROTECTED;
CF.crBackColor=clYellow;
RichEdit1->Perform(EM_SETCHARFORMAT , (WPARAM) SCF_SELECTION , (LPARAM) &CF);
}
void __fastcall TForm1::reset_Highlight()
{
RichEdit1->SelStart=0;
RichEdit1->SelLength=RichEdit1->Text.Length();
CHARFORMAT2 CF;
CF.cbSize=sizeof(CF);
CF.dwMask=CFM_BACKCOLOR;
CF.dwEffects=CFE_PROTECTED;
CF.crBackColor=clWhite;
RichEdit1->Perform(EM_SETCHARFORMAT , (WPARAM) SCF_SELECTION , (LPARAM) &CF);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
reset_Highlight();
String wrd="";
int i=1;
for (i =1; i<=RichEdit1->Text.Length(); i++) {
char ch=RichEdit1->Text[i];
if (ch==' ') {
if (tbl.find(wrd)=="") {
RichEdit1->SelStart=i-1-wrd.Length();
RichEdit1->SelLength=wrd.Length();
Highlight();
}
wrd="";
}
else
{
wrd+=ch;
}
}
if (wrd!="") {
if (tbl.find(wrd)=="") {
RichEdit1->SelStart=i-1-wrd.Length();
RichEdit1->SelLength=wrd.Length();
Highlight();
}
}
}
//---------------------------------------------------------------------------