@think1994 (小白) 注释掉的地方,是我测试时设置的,你可以打开,一步一步的查找原因,这段代码是N年前的东西,对高手而言,确实没什么意义了. 重点修改这个地方: if str<>'' then begin tint:=StrNum(str,','); if (tint>1) and (tint<1001) then begin while Length(str)>0 do //根据解码所得顺序取出所对应的字词 begin j:=StrToInt(Copy(str,1,FindStr(str,',')-1)); if tstr<>'' then begin if Inputtype=0 then begin tstr:=tstr+' '+IntToStr(v)+' '+zw.Strings[j]; end else if Inputtype=1 then begin tstr:=tstr+'^ '+IntToStr(v)+'^ '+zdfhz.Strings[j]; end; v:=v+1; end else begin if Inputtype=0 then begin tstr:='1 '+zw.Strings[j]; end else if Inputtype=1 then begin tstr:='^1 '+zdfhz.Strings[j]; end; v:=v+1; end; str:=Copy(str,FindStr(str,',')+1,(length(str)-FindStr(str,','))); end; end else if tint=1 then begin if Inputtype=0 then begin tstr:=zw.Strings[StrToInt(copy(str,1,length(str)-1))]; end else if Inputtype=1 then begin tstr:=zdfhz.Strings[StrToInt(copy(str,1,length(str)-1))]; end; end else if tint>1000 then Exit; end else Exit;// 汉字编码查找结束 end; if tstr<>'' then s2:=Trim(tstr);
if s2<>'' then t[1]:=s2 else exit;
if HasNum(s2) then begin if ((ord(s2[i])<48) or (ord(s2[i])>57)) then ok:=0;n:=0; for i:=1 to length(s2) do begin if s2[i]=' ' then begin ok:=1-ok; if ok=1 then begin n:=n+1; max:=n; t[n]:=''; end; end; if (((ord(s2[i])<48) or (ord(s2[i])>57))) and (s2[i]<>' ') then begin tn:=n; try t[n]:=t[n]+s2[i]; except end; end; end; //messagebox(0,pchar(t[1]+t[2]+t[3]+t[4]),'提示:',0);--->这是测试用的代码, end; Label1.Text:=''; if tint< 2 then begin if Inputtype=0 then begin Width:=301; Label1.Width:=283; StaticText1.Width:=143; RzBitBtn3.Left:=278; RzBitBtn4.Left:=278; end; Height:=72; label1.Lines.Add(s2); RzBitBtn3.Enabled:=False; RzBitBtn4.Enabled:=False; end else begin if tint>9 then begin for i:=1 to 9 do label1.Lines.Add(inttostr(i)+t[i]); label1.Height:=abs(label1.Font.Height-4)*(9+round(label1.Font.Size*0.15));// Height:=label1.Height; end else begin for i:=1 to tint do label1.Lines.Add(inttostr(i)+t[i]); label1.Height:=abs(label1.Font.Height-4)*(tint+round(label1.Font.Size*0.12)); // Height:=rzbitbtn1.Height+label1.Height; // end; //messagebox(0,pchar(s1),'提示:',0); //调试用 BitMap:= TBitMap.Create; try with BitMap.Canvas do begin X:=trunc(TextWidth(Label1.Text)*0.65);
end; finally BitMap.Free; end; if (label1.Width)<(X) then begin if Inputtype=0 then Width:=x+rzbitbtn3.Width else Width:=X+(RzBitBtn4.Width-8); StaticText1.Width:=StaticText1.Width+(X-Label1.Width+2); label1.Width:=X; RzBitBtn4.Left:=label1.Left+label1.Width-2; RzBitBtn3.Left:=label1.Left+label1.Width-2; end; RzBitBtn3.Enabled:=False; if tn>9 then RzBitBtn4.Enabled:=True else RzBitBtn4.Enabled:=False; end; if (label1.Lines.Count=1) and (cishu=4) then begin song(t[1]); statictext1.Caption:='落寞惊梦'; end; //messagebox(0,pchar(inttostr(label1.Lines.count)),'提示:',0); //调试用 end;
----------------------------------------------
-
在delphi2009 以后 统一了unicode,string 默认unicode 和Delphi7的string不同。汉字不用处理两个字节的问题了 把song()函数中 改成这样 while i<= Length(s) do begin { ch:=byte(s[i]); if Windows.IsDBCSLeadByte(ch)then begin Inc(i);
SendMessage(f3,WM_IME_CHAR,MakeWord(byte(s[i]),ch),0); end else begin SendMessage(f3,WM_IME_CHAR,word(ch),0); end; Inc(i); } SendMessage(f3,WM_IME_CHAR,Integer(s[i]),0); i:=i+1;
这两种开发方式各有特点,IME模式适用于旧版Windows系统,而TSF模式则适用于新版Windows系统,并且提供了更多的功能和更好的用户体验。开发者可以根据目标用户群体和开发需求选择适合的开发方式。 Delphi 是一种高级的编程语言,它可以用来开发基于 Text Service Framework (TSF) 的输入法。然而,由于 Delphi 并非直接支持 COM 组件开发,且 TSF 主要与 C++ 相关联,因此使用 Delphi 开发 TSF 输入法并不常见,也相对复杂。不过,理论上是可行的,因为 Delphi 可以调用 Windows API,并且可以创建 COM 组件。
下面是一个非常基础的示例,展示如何在 Delphi 中开始创建一个简单的 TSF 输入法框架。请注意,这只是一个起点,实际的输入法开发需要更深入的编码和对 Windows TSF 文档的详细了解。
library MyTSFIME; // 你的输入法 DLL 名称
uses Windows, ActiveX, TlHelp32;
// 定义一些必要的 COM 对象和接口 type ITfTextInputProcessor = interface; ITfThreadMgr = interface; ITfClientId = interface;
// DLL 入口点 function DllMain(HInstance: HINST; Reason: DWORD; pvReserved: Pointer): BOOL; stdcall; begin Result := True; // 根据 Reason 进行相应的初始化或清理工作 end;
// 标准 DLL 导出函数 function DllGetClassObject(const CLSID: TCLSID; const IID: TIID; out Obj): HResult; stdcall; begin // 实现 COM 组件的注册和实例化 Result := E_FAIL; end;
function DllCanUnloadNow: HResult; stdcall; begin // 检查是否可以卸载 DLL Result := S_OK; end;
// 导出函数,用于注册和撤销注册 DLL function DllRegisterServer: HResult; stdcall; begin // 实现注册逻辑 Result := S_OK; end;
function DllUnregisterServer: HResult; stdcall; begin // 实现撤销注册逻辑 Result := S_OK; end;
// 你的输入法 COM 对象的实现 type TMyInputProcessor = class(TInterfacedObject, ITfTextInputProcessor) private FClientId: TfClientId; public constructor Create; destructor Destroy; override; // 实现 ITfTextInputProcessor 接口的方法 function Activate(pThreadMgr: ITfThreadMgr; var tfClientId: TfClientId): HResult; stdcall; function Deactivate: HResult; stdcall; end;
请注意,这个代码只是一个框架示例,它没有实现具体的逻辑,并且缺少了很多必要的细节。真正的 TSF 输入法开发需要处理文本输入、编辑、候选词展示、用户界面创建和管理等多个方面的复杂逻辑。如果你不熟悉 COM 和 Windows 文本服务框架,可能需要花费大量的时间来学xi和实现。
----------------------------------------------
《Z-Gantt战石智慧时间管理进度计划甘特图软件》:WWW.Z-SHi.NET