这个问题以前也遇到过,问题出在控件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;