📄 example.pas
字号:
unit Example;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls;
type
//声名函数类型
TICTCLAS_Init=function():boolean; stdcall;
TICTCLAS_Exit=function():boolean; stdcall;
TICTCLAS_ParagraphProcess=function( sSentence,sSentenceResult:PChar):Boolean;stdcall;
THandle=Integer;
TForm1 = class(TForm)
btnCls: TButton;
edtResult: TEdit;
btnQuit: TButton;
btnInit: TButton;
edtInput: TEdit;
StatusBar1: TStatusBar;
Label1: TLabel;
Label2: TLabel;
procedure btnClsClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnInitClick(Sender: TObject);
procedure btnQuitClick(Sender: TObject);
private
{ Private declarations }
initCls: TICTCLAS_Init;
exitCls:TICTCLAS_Exit;
processCls:TICTCLAS_ParagraphProcess;
hasInit:Boolean ;
dllHandle:THandle;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.btnClsClick(Sender: TObject);
var
tmpStr:String;
begin
tmpStr:='';
SetLength(tmpStr, 2000);
processCls(pchar(edtInput.Text),pchar(tmpStr));
edtResult.Text:=trim(tmpStr);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
btnCls.Enabled:=False;
hasInit:=False;
StatusBar1.Panels[0].Text:='请先初始化ICTCLAS!';
end;
procedure TForm1.btnInitClick(Sender: TObject);
begin
if hasInit then exit;
dllHandle:=0;
//将“ICTCLAS.dll”的文件映象映射进调用进程的地址空间,需要指出ICTCLAS.dll的路径
//ICTCLAS.dll在当前路径
dllHandle:=LoadLibrary('ICTCLAS.dll');
if dllHandle=0 then
begin
ShowMessage('初始化失败');
end
else
begin
@initCls:=GetProcAddress(dllHandle,'ICTCLAS_Init'); //
@exitCls:=GetProcAddress(dllHandle,'ICTCLAS_Exit'); //
@processCls:=GetProcAddress(dllHandle,'ICTCLAS_ParagraphProcess');
if (@initCls=nil) then
begin
ShowMessage('调用函数“ICTCLAS_Init”时出错!');
exit;
end;
if (@exitCls=nil) then
begin
ShowMessage('调用函数“ICTCLAS_exit”时出错!');
exit;
end;
if (@processCls=nil) then
begin
ShowMessage('调用函数“ICTCLAS_process”时出错!');
exit;
end;
initCls;
btnCls.Enabled:=true;
btnInit.Enabled:=false;
hasInit:=true;
StatusBar1.Panels[0].Text:='ICTCLAS 初始化成功,您可以进行切分了!';
end;
end;
procedure TForm1.btnQuitClick(Sender: TObject);
begin
if hasInit then exitCls;
//从进程的地址空间中解除“ICTCLAS.dll”
FreeLibrary(dllHandle);
close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -