简体   繁体   English

如何在Delphi中使用此Hyphenation库?

[英]How to use this Hyphenation library in delphi?

This is a hyphenation lib by Synopse delphi open source . 这是Synopse delphi开源断字库

The demo is a console application. 该演示是一个控制台应用程序。 I do not know how to use it in GUI application. 我不知道如何在GUI应用程序中使用它。

Below is my test, but not work. 以下是我的测试,但不起作用。 It does not display word with hyphen (or separaror). 它不显示带有连字符(或分隔符)的单词。 The 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 hyphenated word. 它不显示带连字符的单词。 In the demo, I am also confused about 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 has also enclosed the obj file. 作者还附带了obj文件。 If I want to compile it into a single exe, how to do it? 如果我想将其编译为单个exe,该怎么做?

Can you please help me understand how to use it correctly? 您能帮我了解如何正确使用它吗?

Thanks a lot. 非常感谢。

Disclaimer : I have harnessed a not so recent distribution of Hyphen, it may not be in sync with the latest version . 免责声明 :我利用的不是最近发行的Hyphen,它可能与最新版本不同步。

Here are my points: 这是我的观点:

Compilation of the distribution 发行分布

  • I have compiled it under Delphi 7 and it's OK . 我已经在Delphi 7下编译了它, 没关系

hyphen.rc File hyphen.rc文件

  • There is no hyph_en_EN.dic file in the distribution. 分发中没有hyph_en_EN.dic文件。 If you are going to rebuild hyphen.res, you may need to fix hyphen.rc using the following: 如果要重建hyphen.res,则可能需要使用以下方法修复hyphen.rc

hyphen Text HYPH_EN_US.dic 连字符文本HYPH_EN_US.dic

  • I have not checked the hyphen.res file in the distribution wether it contains hyph_en_EN.dic and/or hyph_en_US.dic . 我尚未检查发行版中的hyphen.res文件是否包含hyph_en_EN.dic和/或hyph_en_US.dic

*.dic Files available in my distribution * .dic文件在我的发行版中可用

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

Answers to the comments in your snippet 片段中评论的答案

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

No! 没有! The correct file extension is .dic . 正确的文件扩展名为.dic You should write instead: 您应该改写:

s := 'hyph_en_US.dic;

The following is Ok (you can refer to the definition of THyphen class): 可以的(可以参考THyphen类的定义):

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

The following is Ok (but it doesn't work because h as a THyphen instance was not properly initialized): 以下是可以的(但是,由于h作为THyphen实例未正确初始化,因此无法正常工作):

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

Your concern about the constructor 您对构造函数的关注

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

It's just one of the proper way to set up THyphen (refer again to the definition of THyphen class among others). 这只是设置THyphen的正确方法THyphen (请再次参考THyphen类的定义)。

Eg: 例如:

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

Harnessing hyphen in a GUI App using Delphi 2007 在使用Delphi 2007的GUI App中利用连字符

  • I can tell that it's OK so long as THyphen instance is properly constructed (Dont forget to include the hyphen.res resource file with {$R hyphen.res} , the hyphen.obj file is already linked in the hyphen.pas unit). 我可以告诉您,只要正确构造了THyphen实例即可(不要忘记将hyphen.res资源文件包含在{$R hyphen.res}hyphen.obj文件已经在hyphen.pas单元中链接了)。

Last but not the least 最后但是同样重要的

I don't have my Delphi install handy, so understand you may need to tweak this a bit. 我没有方便地安装Delphi,因此请了解您可能需要对此进行一些调整。

After looking at the hyphen code, I believe you are using it incorrectly. 查看连字符代码后,我相信您使用的是错误的代码。 The parameter on the constructor is the language or character set. 构造函数上的参数是语言或字符集。

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

or (based on your file name, I think you need this next one) 或(根据您的文件名,我认为您需要下一个)

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

Then "Execute" is used to generate a hyphenated version of the string passed in. "Execute" is a function that returns a new string. 然后,“ Execute”用于生成传入的字符串的连字符版本。“ Execute”是一个返回新字符串的函数。 You are calling it, but not doing anything with the result. 您正在调用它,但是对结果不做任何事情。

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

"NewStr" should now equal "cor-rect". 现在,“ NewStr”应等于“更正”。

If I read the code correctly, the "FillList" function and procedure return a list of all of the possible hyphenation possibilities for the last word that was Execute'd. 如果我正确阅读了代码,则“ FillList”函数和过程将返回已执行的最后一个单词的所有可能的连字符可能性的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM