簡繁體轉換 ( 积分: 100 )

  • 主题发起人 houfuzhu1982
  • 开始时间
H

houfuzhu1982

Unregistered / Unconfirmed
GUEST, unregistred user!
要對窗體的*.DFM做簡繁體轉換,一直弄都不行,(我已事先寫好了Big5ToGB,GBToBig5兩個函數,轉*.Pas文件是正常的)請大俠請點一下
對*.DFM文件要如何做轉換才行.在線等待。本貼實行能者多得分的散分
機制
 
用別的控件,tnt-..或手動改動
 
这个问题以前也遇到过,问题出在控件Caption属性上。参考以下代码。

TLanguage = (
tNone,
tEnglish,
tGBChs,
tBig5,
tGBCht
);

procedure SetFormLanguage(sForm: TForm; SrcLan, DesLan: TLanguage);
var
TmpComp: TComponent;
TmpControl: TControl;
i, j, Len, Index: Integer;
TmpCap: string;
begin
with sForm do
begin
for i := 0 to ComponentCount - 1 do
begin
TmpComp := Components;
//控件Caption
if TmpComp is TControl then
begin
TmpControl := TmpComp as TControl;
Len := TmpControl.GetTextLen; <<-------
if Len <> 0 then
begin
SetString(TmpCap, PChar(nil), Len); <<-------
TmpControl.GetTextBuf(Pointer(TmpCap), Len + 1); <<-------
TmpControl.SetTextBuf(PChar(TranLanguage(TmpCap, SrcLan, DesLan))); <<-------
end;
end;
//其他情况
if TmpComp is TComboBox then
begin
with TmpComp as TComboBox do
begin
Index := ItemIndex;
for j := 0 to Items.Count - 1 do
Items[j] := TranLanguage(Items[j], SrcLan, DesLan);
ItemIndex := Index;
end;
end;

if TmpComp is TLabeledEdit then
begin
with TmpComp as TLabeledEdit do
EditLabel.Caption := TranLanguage(EditLabel.Caption, SrcLan, DesLan);
end;
end;
end;
end;

function TranLanguage(SrcStr: string; SrcLan, DesLan: TLanguage): string;
begin
Result := '';
if SrcLan = DesLan then
begin
Result := SrcStr;
exit;
end;

case SrcLan of
tNone, tEnglish:
exit;
tGBChs:
case DesLan of
tGBCht:
Result := GBChsToCht(SrcStr);
tBig5:
Result := GBToBig5(SrcStr);
end;
tGBCht:
case DesLan of
tGBChs:
Result := GBChtToChs(SrcStr);
tBig5:
Result := GBToBig5(SrcStr);
end;
tBig5:
case DesLan of
tGBChs:
Result := Big5ToGB(SrcStr);
tGBCht:
Result := GBChsToCht(Big5ToGB(SrcStr));
end;
end;
end;
 
关注..........
 
关注。 手工一个个的DFM转我知,自动转我也不会。
 
nicai_wgl的做法,再下不太想用這個方法,缺少靈活性

最好是能用窗體的資源文件來處理,我覺得會較好,直接讀出窗體

定義的內容,接下來跟處理文本的方式一樣,但是有個問題,就是如果是漢字的

話,到文本裡就變成了#1196類似這樣的代碼,現在的問題就是要解決這個編碼的問題
 
view as text 转
 
我上面贴的代码是动态转换窗体语言中的一段,对转换函数做适当修改,应该对大部分窗体都适用。
如果楼主倾向直接转换dfm文件,如果我爱PASCAL所说,view as text 后复制代码到Word中转换字体在复制回来倒是个简便的方法。
:)
 
view as text 后复制代码到Word中转换字体在复制回来倒是个简便的方法?
确实够简便.
处理dfm文件是个好方法,有些简繁转换软件也是这样做的,楼主需要把DFM文件中的
#123456转成汉字,然后再进行简繁体转换,DFM上这个问题的讨论也比较多
 
用我的小工具就更方便了,view as text 全选,点我软件上一菜单,搞定,下载地址:
655778.tomore.com 下的Delphi剑鞘之神鸟,以前的版本不要下,有错。
直接下载:
http://down1.tomore.com/tools/20070101/200701011756452119.rar
 
To nicai_wgl
這幾天寫新任務,忙得忘了,各位,來晚了,不好意思啊,呵呵

我說你的代碼缺少靈活性,主要原因是你的翻譯是
通過判斷控件來完成的,假如一個窗體用了不在你
判斷范圍內的控件,那就失效了,比如用的是第三
方的控件。大家再接討論,希望在這個問題上,能
得到一個好的解決方案
 
希望大家進來,多提一些自已的看法

沒做過的,進來踩踩也行
 
多人接受答案了。
 

Similar threads

顶部