修改构件支持UNICODE指南
安装TntUNICODE控件, 然后修改原ANSI控件.
(1)首先uses TntSystem, TntSysUtils, TntClasses,WideStrUtils{Delphi 2006自带};
{WideParamStr} {WideXXX}
(2)将char改为widechar, pchar改为Pwidechar,string改为widestring, 主要属性为caption, Text, Hint,
还有内部使用的各种TStringList应该改为TtntStringList, TStrings改为TtntStrings,
TFileStream, TMemoryStream, TResourceStream也改为TtntFileStream, TtntMemoryStream, TTntResourceStream
TRegistry改为TTntRegistry;
将ParamStr改为WideParamStr
将ExtractFileXXXX改为WideExtractFileXXXX
(3)涉及到以下例程,
StrLCopy,StrCat,StrPos等以Str开头的PChar处理过程统统改为WStr开头的PWideChar处理过程.
(4)涉及系统例程,
Shell_NotifyIcon->Shell_NotifyIconW
MessageBox->MessageBoxW
(5)对于
Canvas.TextRect(CaptionRect, Caption, [tfNoClip, tfEndEllipsis]);
改为如下类似例程:
WideCanvasTextRect(canvas, CaptionRect, CaptionRect.Left,CaptionRect.Top,Caption);
//TntGraphics;
(6)对于HINT属性,增加
private
function GetHint: WideString;
procedure SetHint(const Value: WideString);
Published
property Hint:WideString read GetHint write SetHint;
function TUNCategoryButtons.GetHint: WideString;
begin
Result := TntControl_GetHint(Self)
end;
procedure TUNCategoryButtons.SetHint(const Value: WideString);
begin
TntControl_SetHint(Self, Value);
end;
增加或修改CM_HINTSHOW消息;
procedure TUNCategoryButtons.CMHintShow(var Message: TMessage{TCMHintShow});message CM_HINTSHOW;
然后在里面增加如下段落:
if Win32PlatformIsUnicode then begin
with TCMHintShow(Message) do begin
if (HintInfo.HintWindowClass = THintWindow) or (HintInfo.HintWindowClass.InheritsFrom(TTntCustomHintWindow)) then begin
if (HintInfo.HintWindowClass = THintWindow) then
HintInfo.HintWindowClass := TTntCustomHintWindow;
HintInfo.HintData := HintInfo;
////////////////////////////////////////////////
self.Hint:=HintStr; //调用此行是为了让TntControl以后能够找到正确的Hint
//因为TntControl将在调用时再次读取HintControl的Hint属性,从而覆盖原来的HintInfo.HintStr
///////////////////////////////////////////////
HintInfo.HintStr := WideGetShortHint(HintStr);
end;
end;
end;
(7)增加Action的支持,修改XXX.ActionChange或者重载:
procedure TBaseButtonItem.ActionChange(Sender: TObject;
CheckDefaults: Boolean);
begin
if Sender is TCustomAction then
with TCustomAction(Sender) do
begin
if not CheckDefaults or (Self.Caption = '') then
Self.Caption := Caption;
if not CheckDefaults or (Self.Hint = '') then
Self.Hint := Hint;
if not CheckDefaults or (Self.ImageIndex = -1) then
Self.ImageIndex := ImageIndex;
if not CheckDefaults or not Assigned(Self.OnClick) then
Self.OnClick := OnExecute;
end;
以上为原有程序段,新增以下程序段即可:
if (Sender is TCustomAction and Supports(Sender, ITntAction) then begin
self.Caption:= TntAction_GetCaption(TCustomAction(Sender));
self.Hint:= TntAction_GetHint(TCustomAction(Sender));
end;
end;