線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1754
推到 Plurk!
推到 Facebook!

多語系Caption 的更改,會找不到某Form 元件

尚未結案
weiliching
初階會員


發表:53
回覆:78
積分:31
註冊:2003-12-27

發送簡訊給我
#1 引用回覆 回覆 發表時間:2013-09-09 14:33:31 IP:211.23.xxx.xxx 訂閱
設計一個改變語系的程式, 就是中英文對換,Caption 
打算寫一個Function 用來把所有元件上的 Caption 更改
Title 文件資料我放在一個Table 裡.
目前設計在自己的Form 裡面找是沒問題的,
但是要改變另一個Form 就會找不到..
因該問題出在於找不到某Form 的原件.
這部份尚不知道怎改?

Function TForm1.M_SetLanguage(M_Form:String):String;
var M_Component:TComponent;
begin

//取出資料Title
With Form1.AdoQueryLang do begin
Close;
Sql.Clear;
Sql.Add('Select * from M_PurchaseLang Where M_Form =:kk');
Parameters.ParamValues['kk'] := M_Form;
Open;
end;
while not Form1.AdoQueryLang.eof do
begin
//有問題的找尋元件.
M_Component := Application.FindComponent( Form1.ADOQueryLang.FieldByName('M_Form').AsString '.' Form1.ADOQueryLang.FieldByName('M_CNName').AsString);
// M_Component := Self.FindComponent( Form1.ADOQueryLang.FieldByName('M_CNName').AsString);

//如果 不為 nil
if Assigned(M_Component) then begin
//如果是Label
if (M_Component is TLabel) then TLabel(M_Component).Caption := Form1.ADOQueryLang.FieldByName('M_Caption').AsString;
end;
Form1.AdoQueryLang.Next;
end;// while not Form1.AdoQueryLang.eof do
weiliching
初階會員


發表:53
回覆:78
積分:31
註冊:2003-12-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2013-09-14 17:28:17 IP:211.23.xxx.xxx 訂閱
問題已解決,最後把他寫成函數,列出來給大家參考,
但是還有一個問題.就是DBGrid 不能用..

Function TForm1.M_SetLanguage(M_Form:String):String;
var M_Component:TComponent;
i,j:Integer;
begin
IF M_Language <>'TW' then begin
With Form1.AdoQueryLang do begin
Close;
Sql.Clear;
Sql.Add('Select * from M_PurchaseLang Where M_Form =:kk');
Parameters.ParamValues['kk'] := M_Form;
Open;
end;
while not Form1.AdoQueryLang.eof do begin
for i:=0 to Application.ComponentCount-1 do begin
if (Application.Components[i].Name = M_Form) and (Application.Components[i] is TForm) then begin
M_Component := Application.Components[i].FindComponent( Form1.ADOQueryLang.FieldByName('M_CNName').AsString );
if Assigned(M_Component) then begin
//如果 a 是 TLabel類的物件
if (M_Component is TLabel) then TLabel(M_Component).Caption := Form1.ADOQueryLang.FieldByName('M_Caption').AsString;
IF (M_Component is TMenuItem) then TMenuItem(M_Component).Caption := Form1.ADOQueryLang.FieldByName('M_Caption').AsString;
if (M_Component is TButton) then TButton(M_Component).Caption := Form1.ADOQueryLang.FieldByName('M_Caption').AsString;
if (M_Component is TTabSheet) then TTabsheet(M_Component).Caption := Form1.ADOQueryLang.FieldByName('M_Caption').AsString;
// if (M_Component is TDBGrid) then TColumn(M_Component).Title.Caption := Form1.ADOQueryLang.FieldByName('M_Caption').AsString;
{ if (M_Component is TColumn) then begin
for j:=0 to M_Component.ComponentCount-1 do begin
M_Component.Column[j].Caption := 'a';
// TTabsheet(M_Component).Title.Caption := Form1.ADOQueryLang.FieldByName('M_Caption').AsString;
end;}
end;// if Assigned(M_Component) then begin
end; // if (Application.Components[i].Name = M_From) then begin
end; // for i:=0 to Application.ComponentCount-1 dobegin
Form1.AdoQueryLang.Next;
end;// while not Form1.AdoQueryLang.eof do
end;// IF M_Language <>'TW' then
end;

系統時間:2024-04-27 11:21:31
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!