高手们帮们呀,谁能帮我将下面的对语言转换部分的函数提取到另一个库单元中形成共有类呀!!

microrain 2001-12-12 02:23:27
//程序源代码

unit main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,IniFiles,
Menus,forms,Dialogs, StdCtrls, ExtCtrls, ScktComp;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
file1: TMenuItem;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
Label3: TLabel;
ComboBox1: TComboBox;
exit1: TMenuItem;
Button3: TButton;

procedure ComboBox1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure SetActiveLanguage(LanguageName:string);

procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
M1:String;
implementation

uses test;




{$R *.dfm}



function SearchLanguagePack:TStrings;
var
ResultStrings:TStrings;
DosError:integer;
SearchRec:TsearchRec;
begin
ResultStrings:=TStringList.Create;
DosError:=FindFirst(ExtractFilePath(ParamStr(0))+'/language/'+'*.ini', faAnyFile, SearchRec);
while DosError=0 do
begin
{ 返回的文件名并去掉末尾的.ini字符 }
ResultStrings.Add(ChangeFileExt(SearchRec.Name,''));
DosError:=FindNext(SearchRec);
end;
FindClose(SearchRec);
Result:=ResultStrings;
end;


procedure TForm1.SetActiveLanguage(LanguageName:string);
const
Translations='Translations';
Messages='Messages';
var
frmComponent:TComponent;
i:Integer;
begin
with TInifile.Create(ExtractFilePath(ParamStr(0))+'/language/'+LanguageName+'.ini') do
begin
for i:=0 to ComponentCount-1 do { 遍历Form组件 }
begin
frmComponent:=Components[i];
if frmComponent is TLabel then { 如果组件为TLabel型则当作TLabel处理,以下同 }
begin
(frmComponent as TLabel).Caption:=
ReadString(Translations,frmComponent.Name
+'.Caption',(frmComponent as TLabel).Caption);
end;
if frmComponent is TCheckBox then
begin
(frmComponent as TCheckBox).Caption:=
ReadString(Translations,frmComponent.Name
+'.Caption',(frmComponent as TCheckBox).Caption);
end;
if frmComponent is TButton then
begin
(frmComponent as TButton).Caption:=
ReadString(Translations,frmComponent.Name
+'.Caption',(frmComponent as TButton).Caption);
(frmComponent as TButton).Hint:=
ReadString(Translations,frmComponent.Name
+'.Hint',(frmComponent as TButton).Hint);
end;
if frmComponent is TMenuItem then
begin
(frmComponent as TMenuItem).Caption:=
ReadString(Translations,frmComponent.Name
+'.Caption',(frmComponent as TMenuItem).Caption);
end;
end;
M1:=ReadString(Messages,'M1',M1);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.AddStrings(SearchLanguagePack);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(M1);
end;


procedure TForm1.ComboBox1Change(Sender: TObject);
begin
SetActiveLanguage(ComboBox1.Text);
end;





procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin

Form2.ShowModal;
Form2.Release;



end;

end.

/////////所调ini文件内容
;///////////////////////////////////////////////////////////////////
; English.ini
;
[Translations]
;
Label1.Caption =text1
Label2.Caption =text2
Label3.Caption =language
Button1.Caption =button1
Button2.Caption =button2
Button3.Caption =exit
Button1.Hint =button1_hint
Button2.Hint =button2_hint
CheckBox1.Caption =CheckBox1
CheckBox2.Caption =CheckBox2
File1.Caption =file
Exit1.Caption =exit
ComboBox1.text =Select language
;
[Messages]
;
M1 =message box test
;
;//////////////////////////////////////////////////////////////////
...全文
107 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
microrain 2001-12-12
  • 打赏
  • 举报
回复
不会吧,没有人帮忙吗??如果帮忙解决这个问题,我给他10bm 具有php+mysql+asp的站点空间。要快呀

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧