開發餐飲POS或是其他系統,如果想打入國際市場的話,都會考量多國語系的問題,大部份就是使用mapping的方式。
在Delphi裡面的做法也很簡單~
先取得form上面的元件數(ComponentCount)
接下來用一個迴圈去比對即可。
資料表也可以開成一個
表單名稱、元件名稱、語言1、語言2、語言3的欄位…
不過因為裡面使用了infopower的wwdbgrid元件,寫在formcreate或formshow都抓不到值,後來是放到FormActivate才順利抓到
以下提供簡單的範例
[pascal]
var
sFormName:String;
i:integer;
begin
sFormName:= Self.Name; // 表單名稱
for i:=0 to self.ComponentCount -1 do begin
if Components[i] is TLabel then begin
if (TLabel(components[i]).Caption <>”) then begin
TLabel(components[i]).Caption := 取得語系….;
end;
end;
if Components[i] is TButton then begin
if (TButton (components[i]).Caption <>”) then begin
TButton (components[i]).Caption := 取得語系….;
end;
end;
end;
end;
[/pascal]
wwDBGrid的話關鍵有:
s:= TwwDBGrid(Components[i]).DataSource.DataSet.Fields[j].FieldName;
TwwDBGrid(Components[i]).ColumnByName(s).DisplayLabel
TwwDBGrid(Components[i]).ColumnByName(s).GroupName
最近在公司開發多國語系的系統,設定資料表跟你相似。但資料表多加物件名稱。
進入程式時從資料庫取得要更改語系的物件,再去更改語系。會呼叫
procedure 更改語系(object_ts, kind_ts: string;value_ts: widestring);
var
object_L : TComponent ;
begin
object_L := findcomponent( object_ts ) ; //先找到該物件
//執行畫面的視窗訊息
if kind_ts = ‘Form’ then
caption := value_ts ;
//找到物件才可更改現的文字
if not ( object_L = nil ) then
begin
//按鈕
if (kind_ts = ‘BitBtn’) then
TBitBtn( object_L ).caption := value_ts ;
//輸入方塊前置說明
if (kind_ts = ‘Label’) then
TLabel( object_L ).caption := value_ts ;
if (kind_ts = ‘CheckBox’) then
TCheckBox( object_L ).caption := value_ts ;
if (kind_ts = ‘GroupBox’) then
TGroupBox( object_L ).caption := value_ts ;
//更改字體
if not FncCheckChineseExist(value_ts) then
begin
TLabel( object_L ).Font.Name := Dm_Ado.USFontName_as ;
end;
end ;
end;
另外為了方便更改語系內容,在程式上多加管理者可以在程式運行當中直接更內容。
此部份可以思考一下要如何做到。有空再上來時再說明。
前台即後台的觀念嗎?感覺很不錯耶~