看看下面代码,我在系统中用到的。
procedure ChangeLangA(Control:TWinControl);
var
PKinds : TTypeKinds;
PList,plist1,plist3: PPropList;
I,J,k: Integer;
i1,j1,k1,o1:integer;
v,v1:TPersistentClass;
co:Tcollection;
f:tfont;
ss:tstrings;
i2,j2,k2:integer;
b:tColumn;
begin
PKinds:=[tkString, tkClass, tkLString,tkwstring];
//改变控件本身属性
i:=GetPropList(Control.ClassInfo,PKinds,Nil);
GetMem(PList,i * SizeOf(Pointer));
i:=GetPropList(Control.ClassInfo,PKinds,PList);
for k:=0 to i-1 do
if Plist[k]^.PropType^.Kind<>tkClass then
setstrprop(Control,Plist[k],gbtobig5(getstrprop(control,Plist[k])))
else
begin
v:=getclass(Plist[k]^.PropType^.Name);
if (v<>nil) and (v=TFont) then
begin
f:=TFont(getobjectprop(control,plist[k]));
f.Charset:=136;
f.Name:=gbtobig5('细明体');
end;
end;
freemem(PList,i * SizeOf(Pointer));
//查找各控件属性,将String属性转换为Big5码
with Control do
for j:=componentcount-1 downto 0 do
begin
if (components[j].classname='TMenuItem') and (Tmenuitem(components[j]).action<>nil) then
continue;
if (components[j] is ttoolbutton)and(Tcontrol(components[j]).parent.name='ToolBar2') then
continue;
i:=GetPropList(components[j].ClassInfo,PKinds,Nil);
GetMem(PList,i * SizeOf(Pointer));
i:=GetPropList(components[j].ClassInfo,PKinds,PList);
for k:=0 to i-1 do
if Plist[k]^.PropType^.Kind<>tkClass then
setstrprop(components[j],Plist[k],gbtobig5(getstrprop(components[j],Plist[k])))
else
//如果控件属性是TCollection类
begin
v:=getclass(Plist[k]^.PropType^.Name);
if (v<>nil) and(v.InheritsFrom(TCollection)) then
begin
co:=Tcollection(getobjectprop(components[j],plist[k]));
for j1:=0 to co.Count-1 do
begin
i1:=GetPropList(co.items[j1].ClassInfo,PKinds,Nil);
GetMem(PList1,i1 * SizeOf(Pointer));
i1:=GetPropList(co.items[j1].ClassInfo,PKinds,PList1);
for k1:=0 to i1-1 do
if Plist1[k1]^.PropType^.Kind<>tkClass then
setstrprop(co.items[j1],Plist1[k1],gbtobig5(getstrprop(co.items[j1],Plist1[k1])));
{else
if co is TDBGridColumns then
begin
b:=TColumn(getobjectprop(co.items[j1],Plist1[k1]));
for i2:=0 to b.PickList.Count-1 do
b.PickList.Strings[i2]:=gbtobig5(b.PickList.Strings[i2]);
b.Title.Font.Name:=gbtobig5('细明体');
end;}
freemem(plist1,i1 * SizeOf(Pointer));
end;
end else
//Tfont属性
if (v<>nil) and (v=TFont) then
begin
f:=TFont(getobjectprop(components[j],plist[k]));
f.Charset:=136;
f.Name:=gbtobig5('细明体');
end else
//Tstrings属性
if (V<>nil) and (V=Tstrings) then
begin
ss:=tstrings(getobjectprop(components[j],plist[k]));
for o1:=0 to ss.Count-1 do
ss.Strings[o1]:=gbtobig5(ss.strings[o1]);
end;
end;
freemem(plist,i * SizeOf(Pointer));
end;
end;