下面是主程序代码和库文件代码
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.

解决方案 »

  1.   

    TForm(y).Caption??
    y不一定是TForm(貌似肯定不是TForm),而且不推荐在dll之间传递对象,RTTI信息会全部失效,除非带包编译
      

  2.   

    假如在程序目录下没有Language.ini文件,程序可以正常退出!
      

  3.   

      TForm(y).Caption:=nName;
        TForm(y).Font.Color:=strtoint(nColor);
        TForm(y).Font.Size:=strtoint(nSize);
        TForm(y).Hint:=nTips;
    你是强制转化出的问题,你不能把不是tform的组件转化为TFORM的
      

  4.   

    我只知道問題出在調用語言庫Loadinifile這個過程上,但是能力有限,光看代碼完全看不出錯誤呀!
      

  5.   

    知道錯的地方啦!但是要怎么改呀?
    TForm(y).Caption:=nName;
        TForm(y).Font.Color:=strtoint(nColor);
        TForm(y).Font.Size:=strtoint(nSize);
        TForm(y).Hint:=nTips;
      

  6.   

    if nLanguage<>'' then
      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;
      

  7.   

    加上IF y is tform then 控制的話就沒有辦法讀出后面的語句來啦!我現在需要的就是
        TForm(y).Caption:=nName; 
        TForm(y).Font.Color:=strtoint(nColor); 
        TForm(y).Font.Size:=strtoint(nSize); 
        TForm(y).Hint:=nTips; 
    這幾句要能夠執行呀!
      

  8.   

    知道錯誤的源泉啦。這句有問題TForm(y).Font.Size:=strtoint(nSize); 
      

  9.   

    直接寫TForm(y).Font.Size:=10;都不行呀!怎么回事哦!