I just purchased Addict Spell Checker to work with TRichView in C++ Builder XE. However, the addict parser does not have a package for C++ Builder XE, and the Readme does not reference C++ Builder XE.
Also, there appears to be an error in the Readme, where it says "Addict 3/4 packages must be changed before installing this package", but it does not say IN WHAT WAY they should be changed.
Can you advise the best way to use Addict with TRichView under C++ Builder XE?
Thanks!
Install Addict Parser with C++ Builder XE
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Thanks. For those finding this post in the future, the post referenced is at http://www.trichview.com/forums/viewtopic.php?p=19627
Note that "Explicit Rebuild" is set on the Options/Description tab (!) and appears to be the default for new C++ Builder XE Projects
Also, I take it from your answer that the ONLY change needed for the Addict 3/4 packages was the change to Explicit Rebuild. However, for C++ Builder, there is no building of Addict in the installation program. In opening the source Addict project for D15, I was prompted to update it for XE. Since I had not built the Addict project, I'm not sure that the build option will be relevant (since XE won't know how to rebuild Addict4 anyway!) Everything seems to work without changing the Addict project -- I will let you know if that changes.
Notes for anyone wanting to build the RichView Addict 4 Parser under C++ Builder XE:
Create a new package (File/New/Package -- C++ Builder) and save it
Add the following files to the package from the downloaded parser:
ad3RichView.pas
ad3RichViewCmpnts.pas
ad3RichVIewFast.pas
Add the following to the requires for the package:
C:\Users\Public\Documents\RAD Studio\8.0\Dcp\RVPkgCBXE.bpi
C:\Program Files (x86)\Addict4\BPL\addict4_d15.bpi
Set the following under Project/Options/Delphi Compiler/Compiling/Other Options/Additional options to pass to the compiler:
-LUDesignIDE
Activate the Release build, and build it. Right click the project and select "Install"
The Demo code for C++ Builder does not compile due to using AnsiStrings, and if you fix that, it fails to link because it references old versions of forms, so I have converted the C++ Builder demo for the TRichView Addict 4 Parser to work with C++ Builder XE:
Create a new C++ Builder XE Project, and drop a TRichViewEdit, TRVStyle, TPopupMenu, TButton, TAddictSpell, and TRVAddictSpell3.
Create the following handlers: FormCreate, RichViewEdit1KeyDown, Button1Click, RichViewEdit1SpellingCheck, RVAddictSpell31ParserIgnoreWord, PopupMenu1Popup
Copy american.adm and autocorrect.adu from Addict4/Dictionaries to the directory containing the .exe you will produce (if you don't, every word will be "misspelled")
Add to the public section of the TForm1 class definition in Unit1.h:
Add the following to the Unit1.cpp file, replacing the handlers created above:
Note that "Explicit Rebuild" is set on the Options/Description tab (!) and appears to be the default for new C++ Builder XE Projects
Also, I take it from your answer that the ONLY change needed for the Addict 3/4 packages was the change to Explicit Rebuild. However, for C++ Builder, there is no building of Addict in the installation program. In opening the source Addict project for D15, I was prompted to update it for XE. Since I had not built the Addict project, I'm not sure that the build option will be relevant (since XE won't know how to rebuild Addict4 anyway!) Everything seems to work without changing the Addict project -- I will let you know if that changes.
Notes for anyone wanting to build the RichView Addict 4 Parser under C++ Builder XE:
Create a new package (File/New/Package -- C++ Builder) and save it
Add the following files to the package from the downloaded parser:
ad3RichView.pas
ad3RichViewCmpnts.pas
ad3RichVIewFast.pas
Add the following to the requires for the package:
C:\Users\Public\Documents\RAD Studio\8.0\Dcp\RVPkgCBXE.bpi
C:\Program Files (x86)\Addict4\BPL\addict4_d15.bpi
Set the following under Project/Options/Delphi Compiler/Compiling/Other Options/Additional options to pass to the compiler:
-LUDesignIDE
Activate the Release build, and build it. Right click the project and select "Install"
The Demo code for C++ Builder does not compile due to using AnsiStrings, and if you fix that, it fails to link because it references old versions of forms, so I have converted the C++ Builder demo for the TRichView Addict 4 Parser to work with C++ Builder XE:
Create a new C++ Builder XE Project, and drop a TRichViewEdit, TRVStyle, TPopupMenu, TButton, TAddictSpell, and TRVAddictSpell3.
Create the following handlers: FormCreate, RichViewEdit1KeyDown, Button1Click, RichViewEdit1SpellingCheck, RVAddictSpell31ParserIgnoreWord, PopupMenu1Popup
Copy american.adm and autocorrect.adu from Addict4/Dictionaries to the directory containing the .exe you will produce (if you don't, every word will be "misspelled")
Add to the public section of the TForm1 class definition in Unit1.h:
Code: Select all
void __fastcall PopupMenuItemClick(TObject *Sender);
void __fastcall PopupMenuAddToDictionaryClick(TObject *Sender);
void __fastcall PopupMenuIgnoreAllClick(TObject *Sender);
Code: Select all
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
RichViewEdit1->Style = RVStyle1;
RichViewEdit1->PopupMenu = PopupMenu1;
RichViewEdit1->Clear();
RichViewEdit1->AddNLATag(
"Speling contest - a kontest in wich you are elimineited if you fale to spel a vord corectly.", 0,0,0);
RichViewEdit1->Format();
RichViewEdit1->StartLiveSpelling();
// remove this line for CB4
PopupMenu1->AutoHotkeys = maManual;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
RVAddictSpell31->CheckRichViewEdit(RichViewEdit1, ctSmart);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RichViewEdit1SpellingCheck(TCustomRichView *Sender, const UnicodeString AWord,
int StyleNo, bool &Misspelled)
{
Misspelled = ! RVAddictSpell31->WordAcceptable(AWord);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RVAddictSpell31ParserIgnoreWord(TObject *Sender, bool Before,
int State)
{
if (!Before &&
(State == IgnoreState_IgnoreAll || State == IgnoreState_Add))
RichViewEdit1->LiveSpellingValidateWord(RVAddictSpell31->CurrentWord);
}
//---------------------------------------------------------------------------
// Before displaying the popup menu, we fill it with suggestions for the
// misspelled word. The clicked misspelled word is selected
// (alternatively, you can select it immediately before the replacement
// in PopupMenuItemClick)
void __fastcall TForm1::PopupMenu1Popup(TObject *Sender)
{
String wrd;
int stl;
TMenuItem *mi;
while (PopupMenu1->Items->Count)
delete PopupMenu1->Items->Items[0];
if (RichViewEdit1->GetCurrentMisspelling(true, wrd, stl))
{
TStringList * sl = new TStringList;
RVAddictSpell31->Suggest(wrd, sl);
for (int i = 0; i<sl->Count; i++)
{
mi = new TMenuItem(PopupMenu1);
mi->Caption = sl->Strings[i];
mi->OnClick = PopupMenuItemClick;
PopupMenu1->Items->Add(mi);
}
if (sl->Count == 0)
{
mi = new TMenuItem(PopupMenu1);
mi->Caption = "(no suggestions)";
mi->Enabled = false;
PopupMenu1->Items->Add(mi);
}
mi = new TMenuItem(PopupMenu1);
mi->Caption = "-";
PopupMenu1->Items->Add(mi);
mi = new TMenuItem(PopupMenu1);
mi->Caption = "&Add to Dictionary";
mi->OnClick = PopupMenuAddToDictionaryClick;
PopupMenu1->Items->Add(mi);
mi = new TMenuItem(PopupMenu1);
mi->Caption = "&Ignore All";
mi->OnClick = PopupMenuIgnoreAllClick;
PopupMenu1->Items->Add(mi);
delete sl;
}
}
// Clicking menu item - menu caption replaces the selected text
void __fastcall TForm1::PopupMenuItemClick(TObject *Sender)
{
/*
The text is already selected in PopupMenu1Popup by calling
GetCurrentMisspelling(True,...).
If you do not want to select misspelled word when displaing the menu,
call GetCurrentMisspelling(False,...) there, and call
GetCurrentMisspelling(True,...) here.
The same is for other PopupMenu*** procedures.
*/
// Make sure that "&" were not added to menu items
// (PopupMenu1->AutoHotkeys must be maManual)
RichViewEdit1->InsertText(((TMenuItem*)Sender)->Caption, false);
}
//---------------------------------------------------------------------------
// Clicking "Add to Dictionary"
void __fastcall TForm1::PopupMenuAddToDictionaryClick(TObject *Sender)
{
String s = RichViewEdit1->GetSelText();
RVAddictSpell31->AddToDictionary(s);
RichViewEdit1->LiveSpellingValidateWord(s);
}
//---------------------------------------------------------------------------
// Clicking "Ignore All"
void __fastcall TForm1::PopupMenuIgnoreAllClick(TObject *Sender)
{
String s = RichViewEdit1->GetSelText();
RVAddictSpell31->AddToIgnoreList(s);
RichViewEdit1->LiveSpellingValidateWord(s);
}
//---------------------------------------------------------------------------
// Autocorrection procedure, which you can copy to use in your application
bool AutoCorrect(TCustomRichViewEdit* rve, TRVAddictSpell3* rvad3)
{
rve = rve->TopLevelEditor;
int ItemNo = rve->CurItemNo;
if (rve->GetItemStyle(ItemNo)<0 ||
rve->Style->TextStyles->Items[rve->GetItemStyle(ItemNo)]->Charset==SYMBOL_CHARSET)
return false;
TRVCodePage CodePage = rve->RVData->GetItemCodePage(ItemNo);
String s = rve->GetItemTextA(ItemNo);
int WordEnd = rve->OffsetInCurItem;
int WordStart = WordEnd;
if (WordStart<1)
return false;
while (WordStart-1>0 && !rve->RVData->IsDelimiterA(s[WordStart-1], CodePage))
WordStart--;
s = s.SubString(WordStart, WordEnd-WordStart);
String s2;
if (rvad3->WordHasCorrection(s,s2))
{
rve->SetSelectionBounds(ItemNo, WordStart, ItemNo, WordEnd);
rve->InsertText(s2, false);
return true;
}
return false;
}
// autocorrection on typing: make sure that autocorrect.adu is installed and
// checked in the options (which it will be by default)
void __fastcall TForm1::RichViewEdit1KeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
switch (Key)
{
case VK_SPACE:
case VK_RETURN:
case VK_TAB:
AutoCorrect(RichViewEdit1, RVAddictSpell31);
}
}
//---------------------------------------------------------------------------
Using the TRVThesaurus3 Thesaurus parser with Addict Spell
I did not find any demos or documentation for the TRVThesaurus3 parser to use the Addict Thesaurus component with TRichView. However, I was able to get functionality similar to the Thesaurus demo for Addict by creating another button to the demo above, and using the following line for the button handler:
RVThesaurus31->LookupRichViewEdit(RichViewEdit1);
Hopefully, I just missed the documentation and demos for the thesaurus -- if anyone knows where they are, please post that info here.
RVThesaurus31->LookupRichViewEdit(RichViewEdit1);
Hopefully, I just missed the documentation and demos for the thesaurus -- if anyone knows where they are, please post that info here.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: