-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit1.pas
1540 lines (1342 loc) · 43.8 KB
/
Unit1.pas
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{*******************************************************}
{ }
{ KBBI Offline }
{ }
{ Copyright (C) 2013 ebsoft.web.id }
{ }
{*******************************************************}
{ KOL MCK } // Do not remove this line!
{$DEFINE KOL_MCK}
unit Unit1;
interface
{$IFDEF KOL_MCK}
uses Windows, Messages, KOL {$IF Defined(KOL_MCK)}{$ELSE}, mirror, Classes,
Controls, mckCtrls, mckObjs, Graphics {$IFEND (place your units here->)}
,ShellAPI,DIUclStreams,UPosX, SHFolder, err, RegExpr;
{$ELSE}
{$I uses.inc}
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
{$ENDIF}
type
TKriteriaCari = (kcMemuat,kcSama,kcDiakhiri,kcDiawali,kcRegex);
TListWord = packed record
x : Integer;
kata : string;
end;
TListWords = array of TListWord;
TListWordType = (wtBold,wtItalic);
TREView = (vNormal,vIndent);
{$IF Defined(KOL_MCK)}
{$I MCKfakeClasses.inc}
{$IFDEF KOLCLASSES} {$I TFMainclass.inc} {$ELSE OBJECTS} PFMain = ^TFMain; {$ENDIF CLASSES/OBJECTS}
{$IFDEF KOLCLASSES}{$I TFMain.inc}{$ELSE} TFMain = object(TObj) {$ENDIF}
Form: PControl;
{$ELSE not_KOL_MCK}
TFMain = class(TForm)
{$IFEND KOL_MCK}
KOLProject1: TKOLProject;
KOLForm1: TKOLForm;
PanelDef: TKOLPanel;
lbKata: TKOLListBox;
REdef: TKOLRichEdit;
PanelTop: TKOLPanel;
ebCari: TKOLEditBox;
PanelWord: TKOLPanel;
lbAdd: TKOLListBox;
PanelMain: TKOLPanel;
Splitter4: TKOLSplitter;
Panel1: TKOLPanel;
LblEf1: TKOLLabelEffect;
LblEf2: TKOLLabelEffect;
Thread1: TKOLThread;
LabelEffect1: TKOLLabelEffect;
btnAbout: TKOLButton;
cbKriteria: TKOLComboBox;
PnlBottom: TKOLPanel;
PnlPageBottom: TKOLPanel;
btnPrev2: TKOLButton;
btnNext2: TKOLButton;
PnlTop: TKOLPanel;
PnlPageTop: TKOLPanel;
btnPrev1: TKOLButton;
btnNext1: TKOLButton;
lblMain: TKOLLabel;
lblAdd: TKOLLabel;
Splitter1: TKOLSplitter;
btnCariKata: TKOLButton;
btnSetting: TKOLButton;
ebKalimat: TKOLEditBox;
Label1: TKOLLabel;
Label2: TKOLLabel;
chTepatSama: TKOLCheckBox;
btnCariArti: TKOLButton;
btnHelp: TKOLButton;
btnRandom: TKOLButton;
procedure KOLForm1FormCreate(Sender: PObj);
procedure ebCariKeyUp(Sender: PControl; var Key: Integer;
Shift: Cardinal);
procedure lbKataSelChange(Sender: PObj);
procedure KOLForm1Close(Sender: PObj; var Accept: Boolean);
procedure lbAddSelChange(Sender: PObj);
procedure LblEf2Click(Sender: PObj);
procedure LblEf2MouseMove(Sender: PControl;
var Mouse: TMouseEventData);
procedure LblEf2MouseLeave(Sender: PObj);
function Thread1Execute(Sender: PThread): Integer;
procedure btnAboutClick(Sender: PObj);
procedure KOLForm1Resize(Sender: PObj);
procedure ebCariChange(Sender: PObj);
procedure cbKriteriaKeyDown(Sender: PControl; var Key: Integer;
Shift: Cardinal);
procedure lbKataKeyUp(Sender: PControl; var Key: Integer;
Shift: Cardinal);
procedure lbAddKeyUp(Sender: PControl; var Key: Integer;
Shift: Cardinal);
procedure REdefKeyUp(Sender: PControl; var Key: Integer;
Shift: Cardinal);
procedure btnNext1Click(Sender: PObj);
procedure btnPrev1Click(Sender: PObj);
procedure btnNext2Click(Sender: PObj);
procedure btnPrev2Click(Sender: PObj);
procedure btnCariKataClick(Sender: PObj);
procedure btnSettingClick(Sender: PObj);
procedure KOLForm1Show(Sender: PObj);
procedure ebKalimatKeyUp(Sender: PControl; var Key: Integer;
Shift: Cardinal);
procedure chTepatSamaClick(Sender: PObj);
procedure btnCariArtiClick(Sender: PObj);
procedure btnHelpClick(Sender: PObj);
procedure cbKriteriaChange(Sender: PObj);
procedure btnRandomClick(Sender: PObj);
procedure KOLForm1KeyUp(Sender: PControl; var Key: Integer;
Shift: Cardinal);
private
{ Private declarations }
//REtmp : TKOLRichEdit;
isSearchArti : Boolean;
curWord,curSearchArti : string;
OldHeight : Integer;
KriteriaCari : TKriteriaCari;
function GetListBold(src : String) : String;
function GetListItalic(src : string) : string;
//function CariKata(const kata : string) : Boolean;
procedure CariKata(const kata : string);
procedure CariArti(const arti : string);
function CariDgRegex(kata: string; const regex : TRegExpr; out lema: String) : Integer;
// Mencari kata dengan regular expresion
// kata akan diubah ke StringList dan diparsing mulai idx=0
// hasil adalah index di kata ke berapa ditemukan mulai dari 1
// jika tidak ditemukan, return value = -1
procedure TampilkanDef(kata :string);
procedure ReadSettings;
procedure SaveFormPosition;
procedure DisplayResult;
procedure DisplayResultMain(page : Integer);
procedure DisplayResultAdd(page : Integer);
// mendapatkan folder khusus, diperlukan sejak adanya UAC
function GetSpecialFolderPath(folder : integer) : string;
public
{ Public declarations }
AppDataDir : string;
end;
var
FMain {$IFDEF KOL_MCK} : PFMain {$ELSE} : TFMain {$ENDIF} ;
word_list,word_def,hasil_all,hasil_main,hasil_add : PStrList;
aListBold,aListItalic : TlistWords;
Tampilan : TREView;
cari : string;
FCurrPageMain,FCurrPageAdd,FJmlPageMain,FJmlPageAdd,FMaxPage : Integer;
AutoSearch : Boolean;
setting : PIniFile;
const JenisKata : array[1..49] of string =
( 'a','a,','n','n,','v','v,','ki','olr','mk v','dik','jk n',
'ar n','ark n','adv','kim','jw a','n dok','v kas','a kim','n kim','n cak',
'jw n','mk a','mk n','cak','s sas','kl n','jp n','met','n geo','ark v',
'min','n min','jw n','n sas','hid','a ki','far','ark kl','tan','lay',
'geo','isl','kris','tern','jw','antr','ek','kl');
VERSI = '1.5.1';
SZ_WORD = 344889; // 1.3 = 345215; // 1.2: 345290; // v1.1 : 318201;
SZ_DEF = 3065456; // 1.3 = 3060838; // 1.2: 3060990; // 2996209;
{
HISTORY
1.3 + Auto search
+ Pencarian berdasar kriteria : sama, diawali, diakhiri, memuat
+ informasi jumlah hasil pencarian + waktu
* Perbaikan beberapa kata dasar dan definisi yang ada tambahan angka
* Fix multi select daftar kata ( set loNoExtendSel = true )
* Perbaikan beberapa kesalahan pewarnaan definisi
1.4
+ Pencarian kata/kalimat dari arti/definisi
+ Opsi pengaturan penggunaan auto search (bawaan tidak aktif)
+ Penjelasan tentang arti singkatan (jenis kata, istilah dll)
+ Icon baru
* Lisensi menjadi Freeware & Open Source
* Perbaikan pencarian kata yg ada tanda - didepannya
* Perbaikan penebalan nomor/urutan arti kata
* Perbaikan beberapa kata yang belum masuk (bising, durian, uang, sarasehan dan romantisisme)
* Perbaikan hasil pencarian lainnya
* Fitur pencarian otomatis tidak aktif secara bawaan (penambahan tombol cari)
* Perbaikan tampilan font yang mengecil di Windows 8
1.5 2013-02-15
* Perbaikan error ketika klik bagian kosong kata utama/tambahan
* Perbaikan setting 'Tepat sama' di pencarian arti
* Perbaikan hasil pencarian arti yang sebelumnya huruf kecil semua
+ Penambahan informasi tooltip menu/button
+ Menu informasi singkatan yg lebih informatif
+ Regular Expression searching
+ Menampilkan kata acak (button 'Rnd' atau Ctrl+R)
1.6 TO DO
* ?=Hasil didaftar yg kurang akurat, misal Pecundang -> Cundang [1]
* Penambahan jenis-kata dari panduan singkatan
+ Penambahan (database) kata oleh pengguna
}
{$IFDEF KOL_MCK}
procedure NewFMain( var Result: PFMain; AParent: PControl );
{$ENDIF}
implementation
uses
USetting, UHelp;
{$IF Defined(KOL_MCK)}{$ELSE}{$R *.DFM}{$IFEND}
{$IFDEF KOL_MCK}
{$I Unit1_1.inc}
{$ENDIF}
{$R WinXP2.RES}
{ $R kbbi.res}
{$R kbbi_acro.RES}
function MyStrReplace(src,sfrom,sto:string): string;
var
i,l,x : Integer;
s : string;
begin
i := PosEx(sfrom,src);
if i = 0 then
begin
Result := src;
Exit;
end;
s :='';
l := Length(sfrom);
x := 1 ;
while i > 0 do
begin
s := s + Copy(src,x,i-x)+sto;
x := i + l;
i := PosEx(sfrom,src,x);
end;
s := s + Copy(src,x,MaxInt);
Result :=s;
end;
{ Mencari daftar kata yang akan di format Bold di RichEdit
Hasilnya adalah string 'src' yang sudah dihilangkan @ dan # }
function TFMain.GetListBold(src : string) : string;
function getTotal: Integer;
var
i1,j1,n1 : Integer;
begin
{ Cari banyaknya @ }
i1 := PosEx('@',src,1);
n1 := 0;
while i1 > 0 do
begin
j1 := PosEx('¶',src,i1);
Inc(n1);
i1:= PosEx('@',src,j1);
end;
Result := n1;
end;
var
n,i,j,k : Integer;
sx,sw,nl,stmp,stmp_b : string;
begin
Result := src;
n := getTotal;
if n = 0 then Exit;
aListBold := nil;
SetLength(aListBold,n);
{ Ingat, semua list_word harus ada penanda awal dan akhir @¶ }
i := PosEx('@',src,1);
n := 0;
{ sx = result }
sx := '';
while i > 0 do
begin
j := PosEx('¶',src,i);
k := j-i-1;
{ sw = string diantara sep[1] dan sep[2] }
sw := Copy(src,i+1,k);
aListBold[n].kata := sw;
{ x=1 untuk kata dasar }
if i = 1 then
aListBold[n].x := 1;
{ tambahkan newline untuk pembatas tipe wtBold }
nl := '';
if i > 3 then
begin
stmp_b := Copy(src,i,4);
{ stmp = string sebelum pembatas awal }
stmp := Copy(src,i-3,4);
{ bukan angka }
if Str2Int(sw) = 0 then
begin
{ newline -> ~; , ;
no newline -> ;-- , ;~ }
if PosFastcodeRTL('@--',stmp_b) > 0 then
begin
case Tampilan of
vNormal : nl :='';
vIndent : begin
nl := #13#10;
{ x=9 untuk indent }
aListBold[n].x :=9;
end;
end;
end
else
if PosFastcodeRTL('~',stmp_b) > 0 then
nl := ''
else
if (PosFastcodeRTL('--',stmp) = 0) and (PosFastcodeRTL(';',stmp) > PosFastcodeRTL('~',stmp)) then
nl := #13#10#13#10
else
nl := '';
end;
end;
{ -- end wtBold -- }
sx := sx + nl + sw ;
i := PosEx('@',src,j);
if i = 0 then
k := Length(src)
else
k := i-j-1;
{ copy string di luar @ dan ¶ }
sx := sx + Copy(src,j+1,k);
Inc(n);
end;
Result := sx;
end;
{ Mencari daftar kata yang akan di format Italic di RichEdit
Hasilnya adalah string 'src' yang sudah dihilangkan # dan ¡ }
function TFMain.GetListItalic(src : string) : string;
function getTotal: Integer;
var
i1,j1,n1 : Integer;
begin
{ Cari banyaknya # }
i1 := PosEx('#',src,1);
n1 := 0;
while i1 > 0 do
begin
j1 := PosEx('¡',src,i1);
Inc(n1);
i1:= PosEx('#',src,j1);
end;
Result := n1;
end;
function TotalNewLine( s2 : string) : Integer;
var
i2,n2 : Integer;
begin
//i2 := PosEx(#13#10#13#10,s2);
i2 := PosEx(#13#10,s2);
n2 := 0;
while i2 > 0 do
begin
i2 := PosEx(#13#10,s2,i2+1);
inc(n2);
end;
Result :=n2;
end;
var
n,i,j,k,l,m : Integer;
sx,sw : string;
begin
Result := src;
n := getTotal;
aListItalic := nil;
if n = 0 then Exit;
SetLength(aListItalic,n);
{ Tidak semua list_italic ada penanda akhir-nya }
i := PosEx('#',src,1);
n := 0;
{ sx = result }
sx := Copy(src,0,i-1);
while i > 0 do
begin
j := PosEx('¡',src,i);
l := j-i-1;
{ sw = string diantara # dan ¡ }
sw := Copy(src,i+1,l);
aListItalic[n].kata := sw;
m := i - (2*n) - 1;
//m := m - TotalNewLine(sx)*2;
m := m - TotalNewLine(sx);
aListItalic[n].x := m;
if j = 0 then { Tidak ditemukan batas akhir }
begin
sx := sx + Copy(src,i+1,MAXWORD);
Break;
end
else
sx := sx + sw ;
i := PosEx('#',src,j);
if i = 0 then
k := MAXWORD
else
k := i-j-1;
{ copy string di luar # dan ¡ }
sx := sx + Copy(src,j+1,k);
Inc(n);
end;
Result := sx;
end;
procedure TFMain.KOLForm1FormCreate(Sender: PObj);
var
r : TREct;
begin
Form.KeyPreview := True;
FMain.Form.Caption := 'KBBI Offline '+VERSI;
LblEf1.Caption := 'Download, update dan informasi terbaru, kunjungi';
LblEf2.Caption := 'http://ebsoft.web.id';
LabelEffect1.Caption := 'Kamus Besar Bahasa Indonesia Luar Jaringan (Luring)';
cbKriteria.Clear;
cbKriteria.Add('Diawali');
cbKriteria.Add('Diakhiri');
cbKriteria.Add('Sama');
cbKriteria.Add('Memuat');
cbKriteria.Add('RegEx');
{ Application Hint }
btnSetting.Hint.Text := 'Buka menu Pengaturan';
btnHelp.Hint.Text := 'Panduan singkat istilah di KBBI Offline';
btnAbout.Hint.Text := 'Tentang Program ini';
btnCariKata.Hint.Text := 'Mencari kata';
btnCariArti.Hint.Text := 'Mencari dari arti kata';
chTepatSama.Hint.Text := 'Pencarian tepat sama huruf kecil dan besar';
btnRandom.Hint.Text := 'Tampilkan kata acak dari KBBI (Ctrl+R)';
LblEf1.Left := (form.Width - ( lblef1.Width + lblef2.Width )) div 2;
LblEf2.Left := LblEf1.Left + LblEf1.Width + 3;
ebCari.DoSetFocus;
word_list := NewStrList;
word_def := NewStrList;
hasil_all := NewStrList;
hasil_main := NewStrList;
hasil_add := NewStrList;
Thread1.Resume;
REdef.perform(EM_GETRECT, 0, lparam(@r));
Inflaterect( r, - 5, - 5 );
REdef.perform(EM_SETRECT, 0, lparam(@r));
Tampilan := vIndent;
OldHeight := Form.Height;
REdef.Font.FontHeight := Round (12 * GetDeviceCaps (REdef.canvas.Handle, LogPixelsY) / 72);
if FileExists(GetStartDir + 'kbbi_config.ini') then
begin
setting := OpenIniFile( GetStartDir + 'kbbi_config.ini');
ReadSettings;
end
else
begin
AppDataDir := GetSpecialFolderPath($001C);
if DirectoryExists(AppDataDir) then
begin
if not DirectoryExists(AppDataDir+'\ebsoft') then
CreateDir(AppDataDir+'\ebsoft');
if not DirectoryExists(AppDataDir+'\ebsoft\kbbi offline') then
CreateDir(AppDataDir+'\ebsoft\kbbi offline');
if DirectoryExists(AppDataDir+'\ebsoft\kbbi offline') then
begin
setting := OpenIniFile( AppDataDir+'\ebsoft\kbbi offline\kbbi_config.ini');
ReadSettings;
end;
end;
end;
if setting.ValueBoolean('NoSound',True) then
//Disable system beep
SystemParametersInfo(SPI_SETBEEP, 0, nil, SPIF_SENDWININICHANGE);
//Enable system beep
//SystemParametersInfo(SPI_SETBEEP, 1, nil, SPIF_SENDWININICHANGE);
end;
{-------------------------------------------------------------------------------
Procedure: TFMain.TampilkanDef
Author: Ebta Setiawan
Arguments: kata :string
Description
- Menampilkan arti dari parameter kata (kata yang dipilih baik main/add)
- Mengatur format font (bold,italic,warna,bck) berbagai kata
-------------------------------------------------------------------------------}
procedure TFMain.TampilkanDef(kata :string);
var
i,j,k,l,sz : Integer;
def,sw,stmp,sl,kd : string;
sublemaMatch : Boolean;
//start : DWORD;
begin
if kata = curWord then Exit;
//REdef.Clear;
REdef.Text := '';
stmp := word_def.Items[str2int(hasil_all.Values[kata])];
stmp := GetListBold(stmp);
def := GetListItalic(stmp);
REdef.Add(def);
//REdef.Font.FontHeight := 16;
REdef.BeginUpdate;
//start := GetTickCount;
k:=0;
for i:= 0 to High(aListBold) do
begin
sw := aListBold[i].kata;
// ambil kata dasarnya
if i = 0 then kd := sw;
l := Length(sw);
if Str2Int(sw) = 0 then
j := REdef.RE_WSearchText(sw,False,False,True,k,-1)
else
j := REdef.RE_WSearchText(sw,False,True,True,k,-1);
if j > -1 then
begin
REdef.SelStart := j ;
REdef.SelLength := l ;
REdef.RE_FmtFontColor := clRed;
sz := REDEf.RE_Font.FontHeight;
if aListBold[i].x = 1 then
begin
{ kata dasar }
REdef.RE_FmtFontSize := Round(sz*1.2);
REdef.RE_FmtBackColor := clYellow;
end
else
begin
REdef.RE_FmtFontSize := Round(sz*1.1);
{ sub lema yang di hilangkan karakter pemisah B7 = #183 }
sl := MyStrReplace(sw,#183,'');
{ kata yg di cari di sub-lema }
l := PosFastcodeRTL('--',sl);
if l = 0 then
begin
l := PosFastcodeRTL('~', sl);
end;
{ Test apakah Cari ada di sub-lema }
if KriteriaCari = kcRegex then
begin
sl := kd + sl;
sl := MyStrReplace(sl,'--','');
sl := MyStrReplace(sl,'~','');
sublemaMatch := PosFastcodeRTL(kata,sl) > 0;
end
else
begin
sublemaMatch := (sl = cari) or ((l>0) and (Pos(cari,sl)>0) );
end;
if sublemaMatch then
begin
REdef.RE_FmtBackColor := clLime;
REdef.RE_FmtFontColor := clBlack;
end;
end;
{ Indent x =9 }
if aListBold[i].x = 9 then
begin
REdef.RE_StartIndent := 200;
REdef.RE_Indent := 240;
end;
REdef.RE_FmtBold := True;
{ Atur Subscript}
l := Length(sw);
{ huruf terakhir-1 adalah integer }
if Str2Int(sw) = 0 then
if Str2Int(sw[l-1])> 0 then
begin
REdef.SelStart := j + Length(sw) - 3;
REdef.SelLength := 3;
REdef.RE_FmtBold := false;
REdef.RE_FmtFontColor := clBlack;
REdef.RE_FmtFontSize := Round(sz*0.8);
REdef.RE_FmtFontOffset := 100;
REdef.RE_FmtBackColor := clWhite;
end;
end;
k := j + Length(sw);
end;
for i:= 0 to High(aListItalic) do
begin
sw := aListItalic[i].kata;
k := aListItalic[i].x;
l := Length(sw);
j := REdef.RE_WSearchText(sw,False,False,True,k,-1);
if j > -1 then
begin
REdef.SelStart := j ;
REdef.SelLength := l ;
if StrIn(LowerCase(Trim(sw)),JenisKata) then
REdef.RE_FmtFontColor := clBlue
else if PosFastcodeRTL('pb',sw) > 0 then
REdef.RE_FmtFontColor := clPurple
else
REdef.RE_FmtFontColor := clGreen;
REdef.RE_FmtItalic := True;
REdef.RE_FmtBold := False;
REdef.RE_FmtBackColor := clWhite;
end;
end;
if isSearchArti then
begin
l := Length(curSearchArti);
j := REdef.RE_WSearchText(curSearchArti,False,False,True,0,-1);
while j > -1 do
begin
REdef.SelStart := j;
REdef.SelLength := l;
REdef.RE_FmtBackColor := clLime;
REdef.RE_FmtFontColor := clBlack;
j := REdef.RE_WSearchText(curSearchArti,False,False,True,j+l,-1);
end;
end;
REdef.EndUpdate;
curWord := kata;
//MsgOK(Int2Ths(GetTickCount-start));
// diulang lagi fungsi pengecekan ini
if not PnlBottom.Visible then
PnlTop.Height := PanelWord.Height
else
PnlTop.Height := (PanelWord.Height - 43) div 2;
end;
procedure TFMain.ebCariKeyUp(Sender: PControl; var Key: Integer;
Shift: Cardinal);
begin
if Key = 13 then
CariKata(ebcari.Text)
end;
procedure TFMain.lbKataSelChange(Sender: PObj);
begin
if lbKata.CurIndex = -1 then Exit;
TampilkanDef(lbKata.Items[lbKata.CurIndex]);
if PnlBottom.Visible and (lbAdd.Count > 0) then
lbAdd.CurIndex := -1;
end;
procedure TFMain.lbAddSelChange(Sender: PObj);
begin
if lbAdd.CurIndex = -1 then Exit;
TampilkanDef(lbAdd.Items[lbAdd.CurIndex]);
lbKata.CurIndex := -1;
end;
procedure TFMain.KOLForm1Close(Sender: PObj; var Accept: Boolean);
begin
SystemParametersInfo(SPI_SETBEEP, 1, nil, SPIF_SENDWININICHANGE);
SaveFormPosition;
word_list.Free;
word_def.Free;
hasil_all.Free;
hasil_main.Free;
hasil_add.Free;
setting.Free;
end;
procedure TFMain.LblEf2Click(Sender: PObj);
begin
ShellExecute(0, 'open', PChar(LblEf2.Caption), '', '', SW_SHOWNORMAL);
end;
procedure TFMain.LblEf2MouseMove(Sender: PControl;
var Mouse: TMouseEventData);
begin
LblEf2.Font.FontStyle := [fsUnderline,fsBold];
LblEf2.Font.Color := clRed;
end;
procedure TFMain.LblEf2MouseLeave(Sender: PObj);
begin
LblEf2.Font.FontStyle := [fsBold];
LblEf2.Font.Color := clBlue;
end;
function TFMain.Thread1Execute(Sender: PThread): Integer;
var
src,dst,rslt : PStream;
begin
Result :=1;
if not FileExists(GetStartDir+'data.dat') then
begin
MsgOK('File database kbbi "data.dat" tidak ditemukan');
Exit;
end;
src := NewReadFileStream(GetStartDir+'data.dat');
dst := NewMemoryStream;
rslt := NewMemoryStream;
Stream2Stream(dst,src,SZ_WORD);
{ Decompress Database }
if NewUclDDStream(rslt,$7D000,dst,nil) then
word_list.LoadFromStream(rslt,False);
dst.Position := 0;
src.Position := SZ_WORD;
Stream2Stream(dst,src,SZ_DEF);
rslt.Position :=0;
if NewUclDDStream(rslt,$7D000,dst,nil) then
word_def.LoadFromStream(rslt,False);
dst.Free;
src.Free;
rslt.Free;
end;
procedure TFMain.btnAboutClick(Sender: PObj);
begin
MsgOK('KBBI Offline Versi '+VERSI+#13#10+
'Freeware ©2010-2013 by Ebta Setiawan'+#13#10#13#10+
'KBBI (Kamus Besar Bahasa Indonesia) Luar Jaringan (offline) dengan mengacu pada data'+#13#10+
'dari KBBI Daring ( edisi III) diambil dari http://pusatbahasa.diknas.go.id/kbbi/'+#13#10+
'Sekarang berganti di http://pusatbahasa.kemdiknas.go.id/kbbi/'+#13#10+
'Database data merupakan hak cipta PusatBahasa'+#13#10+
'Software ini gratis dan bebas disebarluaskan'+#13#10#13#10+
'Download, Informasi, update, dukungan, masukan dan saran melalui:'+#13#10+
'Website: http://ebsoft.web.id'+#13#10+
'Email: [email protected]'
);
end;
procedure TFMain.KOLForm1Resize(Sender: PObj);
begin
LblEf1.Left := ((form.Width - ( lblef1.Width + lblef2.Width )) div 2) - 3;
LblEf2.Left := LblEf1.Left + LblEf1.Width + 3;
end;
procedure TFMain.ebCariChange(Sender: PObj);
begin
if AutoSearch then
begin
if Trim(ebcari.Text) <> '' then
begin
CariKata(ebcari.Text);
end;
ebCari.DoSetFocus;
end;
end;
procedure TFMain.cbKriteriaKeyDown(Sender: PControl; var Key: Integer;
Shift: Cardinal);
begin
if Key = VK_TAB then
ebCari.DoSetFocus;
end;
procedure TFMain.lbKataKeyUp(Sender: PControl; var Key: Integer;
Shift: Cardinal);
begin
if Key = VK_TAB then
if lbAdd.Count > 0 then
lbAdd.DoSetFocus
else
cbKriteria.DoSetFocus;
end;
procedure TFMain.lbAddKeyUp(Sender: PControl; var Key: Integer;
Shift: Cardinal);
begin
if Key = VK_TAB then
cbKriteria.DoSetFocus;
end;
procedure TFMain.REdefKeyUp(Sender: PControl; var Key: Integer;
Shift: Cardinal);
begin
if Key = VK_TAB then
cbKriteria.DoSetFocus;
end;
procedure TFMain.SaveFormPosition;
begin
setting.Mode := ifmWrite;
setting.ValueInteger('width',form.Width);
setting.ValueInteger('height',form.Height);
setting.ValueInteger('top',form.Top);
setting.ValueInteger('left',form.Left);
end;
{-------------------------------------------------------------------------------
Procedure: TFMain.CariKata
Author: Ebta Setiawan
Arguments: const kata: string
Description
- Pencarian utama dari kata yang dimasukkan user
- Hasil yang ditemukan dimasukkan dalam list main, add & all (main+add)
-------------------------------------------------------------------------------}
procedure TFMain.CariKata(const kata: string);
var
i,k,m,n : Integer;
start :DWORD;
s,sk,sd : KOLstring;
pCari : PAnsiChar;
re : TRegExpr;
reHasil : string;
begin
hasil_main.Clear;
hasil_add.Clear;
hasil_all.Clear;
start := GetTickCount;
//j:=0; {Jumlah hasil_main ditemukan}
//t:=0; {Jumlah hasil yang PosFastcodeRTL() = 1}
cari := LowerCase(trim(kata));
if trim(cari) = '' then Exit;
{ Kriteria Pencarian }
if cbKriteria.Text = 'Diawali' then KriteriaCari := kcDiawali else
if cbKriteria.Text = 'Diakhiri' then KriteriaCari := kcDiakhiri else
if cbKriteria.Text = 'Sama' then KriteriaCari := kcSama else
if cbKriteria.Text = 'Memuat' then KriteriaCari := kcMemuat else
if cbKriteria.Text = 'RegEx' then
begin
KriteriaCari := kcRegex;
re := TRegExpr.Create;
re.Expression := kata;
end;
{ Yang dicari 1 huruf saja }
if Length(cari) = 1 then
begin
if Str2Int(cari) = 0 then
if cari[1] in ['a' .. 'z'] then
cari := UpperCase(cari)+', '+cari;
end;
isSearchArti := False;
pCari := Pointer(cari);
{ Mulai Pencarian word_list }
for i:=0 to word_list.Count-1 do
begin
s := word_list.ItemPtrs[i];
if KriteriaCari = kcRegex then
m := CariDgRegex(s,re,reHasil)
else
m := Pos2(pCari,word_list.ItemPtrs[i]);
if m > 0 then
begin
{ cari batas terakhir word_list pertama }
k := PosFastcodeRTL('|',s);
{ !!PENTING... semua string harus ada pembatas akhir "|" }
{ Ambil word_list pertama }
if k > 0 then
sk := Copy(s,1,k-1);
sd := sk;
n := PosFastcodeRTL('^',sk);
{ ubah tanda ^N jika ada }
if n > 0 then
begin
{ sd : string kata dasar }
sd := Copy(sd,1,n-1);
StrReplace(sk,'^',' [');
sk := sk+']';
if k > 0 then k := k+2;
end;
{ tambahkan index word_def, khusus regex,
tambahkan hasil lema yang ditemukan, bukan kata dasarnya }
if KriteriaCari = kcRegex then
sk := reHasil + '=' + Int2Str(i)
else
sk := sk + '=' + Int2Str(i);
{ Semua hasil yg ditemukan, kelompokkan berdasar kriteria }
case KriteriaCari of
kcDiawali : if m = 1 then hasil_all.Add(sk);
kcDiakhiri : if k = (m + Length(cari)) then hasil_all.Add(sk);
kcSama : if sd = cari then hasil_all.Add(sk);
kcMemuat,kcRegex : hasil_all.Add(sk);
end;
{ Tambahkan index pos dengan 2 digit, untuk sorting
fix in 1.3 : cari:abu -> kok abu-abu yg pertama..}
if m = 1 then
begin
//Inc(t);
if (length(sd) > Length(cari)) then
sk := '02' + sk
else
sk := '01' + sk
end
else
sk := '07' + sk;
{ Pisah jika yg dicari di word_list pertama }
case KriteriaCari of
kcDiawali : if m = 1 then hasil_main.Add(sk);
kcDiakhiri : if k = (m + Length(cari)) then
if m < k then hasil_main.Add(sk)
else hasil_add.Add(sk);
kcSama : if sd = cari then hasil_main.Add(sk);
kcMemuat,kcRegex : if m < k then hasil_main.Add(sk)
else hasil_add.Add(sk);
end;
//Inc(j);
//if t = MaxList then Break;
end;
end;
DisplayResult;
Form.StatusText[0] := PChar(' Ditemukan '+ Int2Ths(hasil_all.Count)+ ' kata (' +
Int2Ths(GetTickCount-start) + 'ms)');
end;
{-------------------------------------------------------------------------------
Procedure: TFMain.DisplayResult
Author: Ebta Setiawan
Arguments: None
Description
- Menampilkan daftar kata utama dan tambahan setelah pencarian
- Menampilkan paging pertama main & add
- Memilih/select hasil kata pertama (index=0) main/add jika ada
- menampilkan informasi jika pencarian tidak menemukan data
-------------------------------------------------------------------------------}
procedure TFMain.DisplayResult;
var
i,j,k,jml : Integer;
s : string;
//start : DWORD;
begin
//start := GetTickCount;
{ Sort }
hasil_main.Sort(False);
lbKata.Clear;