uLanguage.pas

//author: cxg

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

procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBox1.Items.AddStrings(SearchLanguagePack);
end;
}

unit uLanguage;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Menus, IniFiles, ComCtrls, ExtCtrls,
  cxButtons    
  ;

var
  g_hash: THashedStringList;

//搜索ini文件生成语言列表
function SearchLanguagePack: TStrings;
//根据当前选择的语言设置指定窗体及其子控件的属性
procedure SetActiveLanguage(owner: TForm; const LanguageName: string);
//将指定窗体及其子控件的属性写入INI文件
procedure Writeproperty(owner: TForm; const LanguageName: string);

function GetHash: THashedStringList;
function GetHashStr(const key: string): string;
procedure SetLanguage(owner: TForm);
procedure WriteLangIni(owner: tform);

implementation

function GetHash: THashedStringList;
var
  ini: TIniFile;
begin
  ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'system.ini');
  Result := THashedStringList(THandle(ini.ReadInteger('pointer', 'hash', 0)));
  ini.Free;
end;

function GetHashStr(const key: string): string;
begin
  Result := GetHash.Values[key];
end;

function _WriteLangIni: Boolean;
var
  ini: TIniFile;
begin
  ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'system.ini');
  Result := ini.ReadBool('language', 'writelangini', false);
  ini.Free;
end;

procedure WriteLangIni(owner: tform);
begin
  if _WriteLangIni then
    uLanguage.Writeproperty(owner, 'chinese(gb)');
end;

procedure SetLanguage(owner: TForm);
var
  ini: TIniFile;
begin
  ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'system.ini');
  uLanguage.SetActiveLanguage(owner, ini.ReadString('language', 'currentlanguage', 'chinese(gb)'));
  ini.Free;
end;

function SearchLanguagePack: TStrings;
var
  ResultStrings: TStrings;
  DosError: integer;
  SearchRec: TsearchRec;
begin
  ResultStrings := TStringList.Create;
  DosError := FindFirst(ExtractFilePath(Application.ExeName) + '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 Writeproperty(owner: TForm; const LanguageName: string);
var
  c: TComponent;
  i: Integer;
begin
  if owner = nil then exit;
  with TInifile.Create(ExtractFilePath(Application.ExeName) + 'language/' + LanguageName + '.ini') do
  begin
    WriteString(owner.Name, owner.Name + '.Caption', owner.Caption);
    for i := 0 to owner.ComponentCount - 1 do
    begin
      c := owner.Components[i];
      if c is TLabel then
      begin
        writeString(owner.Name, c.Name + '.Caption', (c as TLabel).Caption);
      end else
        if c is TLabeledEdit then
        begin
          writeString(owner.Name, c.Name + '.EditLabel.Caption', (c as TLabeledEdit).EditLabel.Caption);
        end else
          if c is TCheckBox then
          begin
            writeString(owner.Name, c.Name + '.Caption', (c as TCheckBox).Caption);
          end else
            if c is TButton then
            begin
              writeString(owner.Name, c.Name + '.Caption', (c as TButton).Caption);
              writeString(owner.Name, c.Name + '.Hint', (c as TButton).Hint);
            end else
              if c is TcxButton then
              begin
                writeString(owner.Name, c.Name + '.Caption', (c as TcxButton).Caption);
                writeString(owner.Name, c.Name + '.Hint', (c as TcxButton).Hint);
              end else
                if c is TMenuItem then
                begin
                  writeString(owner.Name, c.Name + '.Caption', (c as TMenuItem).Caption);
                end else
                  if c is TToolButton then
                  begin
                    writeString(owner.Name, c.Name + '.Caption', (c as TToolButton).Caption);
                    writeString(owner.Name, c.Name + '.Hint', (c as TToolButton).Hint);
                  end else
                    if c is TTabSheet then
                    begin
                      writeString(owner.Name, c.Name + '.Caption', (c as TTabSheet).Caption);
                    end; 
    end;
  end;
end;

procedure SetActiveLanguage(owner: TForm; const LanguageName: string);
const
  Messages = 'Messages'; //字符串变量小节
var
  c: TComponent;
  i: Integer;
  ini: TIniFile;
begin
  if owner = nil then exit;
  ini := TInifile.Create(ExtractFilePath(Application.ExeName) + 'language/' + LanguageName + '.ini');
  with ini do
  begin
    owner.Caption := readstring(owner.Name, owner.Name + '.Caption', owner.Caption);
    for i := 0 to owner.ComponentCount - 1 do
    begin
      c := owner.Components[i];
      if c is TLabel then
      begin
        (c as TLabel).Caption := ReadString(owner.Name, c.Name + '.Caption', (c as TLabel).Caption);
      end else
        if c is TLabeledEdit then
        begin
          (c as TLabeledEdit).EditLabel.Caption := ReadString(owner.Name, c.Name + '.EditLabel.Caption', (c as TLabeledEdit).EditLabel.Caption);
        end else
          if c is TCheckBox then
          begin
            (c as TCheckBox).Caption := ReadString(owner.Name, c.Name + '.Caption', (c as TCheckBox).Caption);
          end else
            if c is TButton then
            begin
              (c as TButton).Caption := ReadString(owner.Name, c.Name + '.Caption', (c as TButton).Caption);
              (c as TButton).Hint := ReadString(owner.Name, c.Name + '.Hint', (c as TButton).Hint);
            end else
              if c is TcxButton then
              begin
                (c as TcxButton).Caption := ReadString(owner.Name, c.Name + '.Caption', (c as TcxButton).Caption);
                (c as TcxButton).Hint := ReadString(owner.Name, c.Name + '.Hint', (c as TcxButton).Hint);
              end else
                if c is TMenuItem then
                begin
                  (c as TMenuItem).Caption := ReadString(owner.Name, c.Name + '.Caption', (c as TMenuItem).Caption);
                end else
                  if c is TToolButton then
                  begin
                    (c as TToolButton).Caption := ReadString(owner.Name, c.Name + '.Caption', (c as TToolButton).Caption);
                    (c as TToolButton).Hint := ReadString(owner.Name, c.Name + '.Hint', (c as TToolButton).Hint);
                  end else
                    if c is TTabSheet then
                    begin
                      (c as TTabSheet).Caption := ReadString(owner.Name, c.Name + '.Caption', (c as TTabSheet).Caption);
                    end; 
    end;
    ReadSectionValues('messages', g_hash);
  end;
  ini.Free;
  ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'system.ini');
  ini.WriteInteger('pointer', 'hash', thandle(g_hash));
  ini.Free;
end;

initialization
  g_hash := THashedStringList.Create;
finalization
  FreeAndNil(g_hash);

end.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: delphitwain.pas 是一个在Delphi中实现TWAIN接口的单元文件。它包含了一系列的函数和过程,用于与TWAIN驱动程序进行通信,实现图像采集和处理的功能。 delphitwainutils.pas 是一个辅助单元文件,它包含了一些用于简化TWAIN接口调用的函数和过程。这些函数和过程提供了一些常用的操作,如打开和关闭TWAIN设备、设置扫描参数、开始和结束图像采集等。 twain.pas 是一个TWAIN接口的定义文件,它包含了一系列的常量、类型和函数的声明,用于描述和操作TWAIN驱动程序的接口。 delphitwain.chm 是一个Delphi TWAIN组件的帮助文件,它提供了关于组件的详细信息、使用说明和示例代码。通过这个帮助文件,开发人员可以更方便地了解和使用Delphi TWAIN组件。 delphitwain.c 是一个C语言的原始代码文件,用于实现与TWAIN驱动程序的交互功能。它可能是Delphi TWAIN组件的底层实现,也可以是与Delphi TWAIN组件配套使用的其他组件或库的源代码文件。 ### 回答2: 由于提供的信息不够详细,所以无法准确回答你的问题。下面是对所提及文件的简要解释: 1. delphitwain.pas: 这是一个Pascal语言编写的Delphi TWAIN库的单元文件。TWAIN是一种用于扫描仪和图像设备的标准接口,可以在Delphi应用程序中使用该库来实现与扫描仪的交互。 2. delphitwainutils.pas: 这是Delphi TWAIN库的辅助单元文件,可能包含了一些用于扫描图像处理的实用函数和过程。 3. twain.pas: 这是一个与TWAIN接口相关的Pascal单元文件。通常用于与扫描仪进行通信和控制。 4. delphitwain.chm: 这是一个帮助文档文件,可能包含了关于Delphi TWAIN库的使用说明、函数和过程的说明等信息。通常可以通过点击相应的函数或过程来获取更详细的帮助信息。 5. delphitwain.c: 这是一个C语言编写的Delphi TWAIN库的源代码文件。可能包含了Delphi TWAIN库的实现细节和相关函数的定义。 需要注意的是,以上仅是对所提及文件的一般解释,具体功能和用途还需要根据实际情况来确定,比如具体的函数和过程定义等。如果有更详细的问题或者需要更具体的信息,请您提供更多细节,以便进行更准确的回答。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值