下面是主程序代码和库文件代码
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Label1: TLabel;
CheckBox1: TCheckBox;
ListBox1: TListBox;
GroupBox1: TGroupBox;
Button6: TButton;
Button7: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationprocedure Getinifile(x:Integer;y:TComponent);stdcall;external 'language.dll' name 'Getinifile';
procedure Copyinifile;stdcall;external 'language.dll' name 'Copyinifile';
procedure Loadinifile(x:Integer;y:TComponent);stdcall;external 'language.dll' name 'Loadinifile';{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
Showmessage('ddddd');
end;procedure TForm1.FormCreate(Sender: TObject);
var
i:Integer;
begin
for i := 1 to Componentcount do
begin
Getinifile(i,Components[i-1]);
Loadinifile(i,Components[i-1]); //主要是调用这个过程时出的问题
end;
Copyinifile;
end;
end.
program Project1;uses
ShareMem,
Forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
library language;uses
ShareMem,
SysUtils,
Classes,
IniFiles,
Forms,
Windows;{$R *.res}procedure Getinifile(x:Integer;y:TComponent); stdcall;
var
IniFile: TIniFile;
begin
{生成語言庫}
IniFile:=TInifile.Create(ExtractFilePath(ParamStr(0))+'test.ini');
IniFile.WriteString('Language','Language','en');
IniFile.WriteInteger('FormCount','Count',1);
IniFile.WriteInteger('Form'+IntToStr(1),'Total',x);
IniFile.WriteString('Form'+IntToStr(1),'FormCaption','Form'+IntToStr(1));
iniFile.WriteString('Form'+IntToStr(1),'Label'+IntToStr(x),TForm(y).Caption+'^'+TForm(y).ClassName+'^'+''+'^'+inttostr(TForm(y).Font.Color)+'^'+inttostr(TForm(y).Font.Size)+'^'+TForm(y).Hint+'^'+'');
iniFile.Destroy;
end;procedure Copyinifile; stdcall;
begin
{生成新的語言庫}
copyfile('test.ini' ,'Demo.ini',false);
deletefile('test.ini');
end;function SplitStr(var Text:Shortstring;SplitChar:Shortstring): ShortString; stdcall;//截取字串
var
sF: ShortString;
begin
sF := '';
if Text <> '' then
if Pos(SplitChar, Text) > 0 then
begin
sF := Copy(Text, 1, Pos(SplitChar, Text) - 1);
Text := Copy(Text, Pos(SplitChar, Text) + 1, MaxInt);
end
else
begin
sF := Text;
Text := '';
end;
Result := sF;
end;procedure Loadinifile(x:Integer;y:TComponent); stdcall;
var
IniFile: TIniFile;
slabel,nName,nLanguage,nShortcuts,nColor,nSize,nTips,nRes: ShortString;
begin
{調用語言庫}
IniFile:=TInifile.Create(ExtractFilePath(ParamStr(0))+'Language.ini');
slabel:=IniFile.ReadString('Form'+IntToStr(1),'Label'+IntToStr(x),'');
nName:=SplitStr(slabel,'^');
nLanguage:=SplitStr(slabel,'^');
nShortcuts:=SplitStr(slabel,'^');
nColor:=SplitStr(slabel,'^');
nSize:=SplitStr(slabel,'^');
nTips:=SplitStr(slabel,'^');
nRes:=SplitStr(slabel,'^');
if nLanguage<>'' then
begin
TForm(y).Caption:=nName;
TForm(y).Font.Color:=strtoint(nColor);
TForm(y).Font.Size:=strtoint(nSize);
TForm(y).Hint:=nTips;
end;
end;exports
Getinifile,Copyinifile,Loadinifile;begin
end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Label1: TLabel;
CheckBox1: TCheckBox;
ListBox1: TListBox;
GroupBox1: TGroupBox;
Button6: TButton;
Button7: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationprocedure Getinifile(x:Integer;y:TComponent);stdcall;external 'language.dll' name 'Getinifile';
procedure Copyinifile;stdcall;external 'language.dll' name 'Copyinifile';
procedure Loadinifile(x:Integer;y:TComponent);stdcall;external 'language.dll' name 'Loadinifile';{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
Showmessage('ddddd');
end;procedure TForm1.FormCreate(Sender: TObject);
var
i:Integer;
begin
for i := 1 to Componentcount do
begin
Getinifile(i,Components[i-1]);
Loadinifile(i,Components[i-1]); //主要是调用这个过程时出的问题
end;
Copyinifile;
end;
end.
program Project1;uses
ShareMem,
Forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
library language;uses
ShareMem,
SysUtils,
Classes,
IniFiles,
Forms,
Windows;{$R *.res}procedure Getinifile(x:Integer;y:TComponent); stdcall;
var
IniFile: TIniFile;
begin
{生成語言庫}
IniFile:=TInifile.Create(ExtractFilePath(ParamStr(0))+'test.ini');
IniFile.WriteString('Language','Language','en');
IniFile.WriteInteger('FormCount','Count',1);
IniFile.WriteInteger('Form'+IntToStr(1),'Total',x);
IniFile.WriteString('Form'+IntToStr(1),'FormCaption','Form'+IntToStr(1));
iniFile.WriteString('Form'+IntToStr(1),'Label'+IntToStr(x),TForm(y).Caption+'^'+TForm(y).ClassName+'^'+''+'^'+inttostr(TForm(y).Font.Color)+'^'+inttostr(TForm(y).Font.Size)+'^'+TForm(y).Hint+'^'+'');
iniFile.Destroy;
end;procedure Copyinifile; stdcall;
begin
{生成新的語言庫}
copyfile('test.ini' ,'Demo.ini',false);
deletefile('test.ini');
end;function SplitStr(var Text:Shortstring;SplitChar:Shortstring): ShortString; stdcall;//截取字串
var
sF: ShortString;
begin
sF := '';
if Text <> '' then
if Pos(SplitChar, Text) > 0 then
begin
sF := Copy(Text, 1, Pos(SplitChar, Text) - 1);
Text := Copy(Text, Pos(SplitChar, Text) + 1, MaxInt);
end
else
begin
sF := Text;
Text := '';
end;
Result := sF;
end;procedure Loadinifile(x:Integer;y:TComponent); stdcall;
var
IniFile: TIniFile;
slabel,nName,nLanguage,nShortcuts,nColor,nSize,nTips,nRes: ShortString;
begin
{調用語言庫}
IniFile:=TInifile.Create(ExtractFilePath(ParamStr(0))+'Language.ini');
slabel:=IniFile.ReadString('Form'+IntToStr(1),'Label'+IntToStr(x),'');
nName:=SplitStr(slabel,'^');
nLanguage:=SplitStr(slabel,'^');
nShortcuts:=SplitStr(slabel,'^');
nColor:=SplitStr(slabel,'^');
nSize:=SplitStr(slabel,'^');
nTips:=SplitStr(slabel,'^');
nRes:=SplitStr(slabel,'^');
if nLanguage<>'' then
begin
TForm(y).Caption:=nName;
TForm(y).Font.Color:=strtoint(nColor);
TForm(y).Font.Size:=strtoint(nSize);
TForm(y).Hint:=nTips;
end;
end;exports
Getinifile,Copyinifile,Loadinifile;begin
end.
解决方案 »
- 求指点
- 编写组件,如何添加外部事件?
- 在这里为什么要加三个单引号??
- 小调查,进者有分!!!!
- 求助:控件在DBGrid某一标题栏中位置的固定问题---急!!!
- 一奇怪的问题.!不清楚什么意思.!
- 请kylincn(随心所欲),lianghu(山人)进来拿分; 另外 斑竹帮我给分http://www.csdn.net/expert/topic/389/389544.shtm
- 如何判断BLOB学段是否为空?
- 请问如何开发一个关于格斗游戏的快捷键。
- 怎么判断计算机是否已经连上Internet了?
- 急,FastReport 中richtext内容显示不全?只有特定的字号能显示
- ★★ 今天偶也来严重鄙视 “回复太快!如果你是恶意刷楼,将会受到严厉惩罚!” ★★
y不一定是TForm(貌似肯定不是TForm),而且不推荐在dll之间传递对象,RTTI信息会全部失效,除非带包编译
TForm(y).Font.Color:=strtoint(nColor);
TForm(y).Font.Size:=strtoint(nSize);
TForm(y).Hint:=nTips;
你是强制转化出的问题,你不能把不是tform的组件转化为TFORM的
TForm(y).Caption:=nName;
TForm(y).Font.Color:=strtoint(nColor);
TForm(y).Font.Size:=strtoint(nSize);
TForm(y).Hint:=nTips;
begin
IF y is tform then
begin
TForm(y).Caption:=nName;
TForm(y).Font.Color:=strtoint(nColor);
TForm(y).Font.Size:=strtoint(nSize);
TForm(y).Hint:=nTips;
end;
end;
TForm(y).Caption:=nName;
TForm(y).Font.Color:=strtoint(nColor);
TForm(y).Font.Size:=strtoint(nSize);
TForm(y).Hint:=nTips;
這幾句要能夠執行呀!