How to use this Hyphenation library in delphi?

This is decrypting lib using Synopse delphi open source .

Demo is a console application. I do not know how to use it in a graphical application.

Below is my test, but not work. It does not display a word with a hyphen (or separator). Lib can be downloaded here:

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, hyphen, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private procedure testhyphenator; { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} { TForm1 } procedure TForm1.testhyphenator; var h: THyphen; s: string; F, L: Integer; begin s := 'hyph_en_US.txt'; //this is from the folder, is that correct to call? if FileExists(s) then begin F := FileOpen(s, fmOpenRead); L := FileSeek(F, 0, soFromEnd); if L > 0 then begin SetLength(s, L); FileSeek(F, 0, soFromBeginning); FileRead(F, s[1], L); end; FileClose(F); end; h := THyphen.Create(s); h.Execute('pronunciation'); //is this correct? ShowMessage(h.filllist); //not display hyphenated word end; 

It does not display a hyphen word. In the demo, I also got confused in the constructor:

 H := THyphen.create('ISO8859-1'#10'f1f'#10'if3fa/ff=f,2,2'#10'tenerif5fa'); writeln('"',H.Execute('SchiffahrT'),'"'); writeln(H.FillList); ... 

The author also attached the obj file. If I want to compile it into one exe, how to do it?

Could you help me understand how to use it correctly?

Many thanks.

0
source share
2 answers

Disclaimer: I used a not so recent Hyphen distribution, it may not be synchronized with the latest version .

Here are my points:

Distribution compilation

  • I compiled it under Delphi 7 and OK .

Hyphen.rc file

  • There is no hyph_en_EN.dic file in the distribution . If you intend to rebuild hyphen.res, you may need to fix hyphen.rc using the following:

hyphen Text HYPH_EN_US.dic

  • I did not check the hyphen.res file on the distribution that contains hyph_en_EN.dic and / or hyph_en_US.dic .

*. dic Files available in my distribution

  • hyph_it_IT.dic
  • hyph_es_ES.dic
  • hyph_fr_FR.dic
  • hyp_en_US.dic
  • hyp_de_DE.dic

Responses to comments in your snippet

 s := 'hyph_en_US.txt'; //this is from the folder, is that correct to call? 

Not! The correct .dic file .dic . Instead, you should write:

 s := 'hyph_en_US.dic; 

The following is Ok (you can refer to the definition of the THyphen class):

 Execute('pronunciation'); // is this correct? 

Next, Ok is executed (but this does not work, because h as an instance of THyphen not initialized correctly):

 ShowMessage(h.filllist); //not display hyphenated word 

Your concern for the constructor

 H := THyphen.create('ISO8859-1'#10'f1f'#10'if3fa/ff=f,2,2'#10'tenerif5fa'); 

This is just one of the correct ways to configure THyphen (refer to the definition of the THyphen class THyphen ).

eg:.

 H := THyphen.create('EN'); 

Using hyphens in a graphical application using Delphi 2007

  • I can say that it is OK as long as the THyphen instance THyphen correctly constructed (remember to include the hyphen.res resource hyphen.res with {$R hyphen.res} , the hyphen.obj file hyphen.obj already linked in the hyphen.pas block).

Last but not least

  • Feel free to contact Arno Bushey the great man behind Synopse . He is a member of Stackoverflow and is always ready to help for sure, the top delphi user in addition.
+2
source

I do not have my Delphi installation, so understand that you may need to configure it a bit.

Looking at the hyphen code, I believe that you are using it incorrectly. A parameter in the constructor is a language or character set.

 h := THyphen.Create('UTF-8'); 

or (depending on your file name, I think you need the following)

 h := THyphen.Create('EN'); 

Then, "Execute" is used to generate the wrapping string of the wrapping string. "Execute" is a function that returns a new line. You name it, but do nothing with the result.

 NewStr := h.Execute('correct'); 

"NewStr" should now be equal to "correct."

If I read the code correctly, the FillList function and procedure will return a list of all possible hyphenation options for the last word that was executed.

+1
source

All Articles