⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lblanguage.pas

📁 天涯進銷存系統
💻 PAS
字号:
unit LBLanguage;

interface

uses
  Menus, DBCtrls, DB, ADODB, DBGrids, ComCtrls, Grids, CheckLst,
  ExtCtrls, Buttons, StdCtrls, Dialogs, Windows, Messages,
  SysUtils, Classes, Forms, Inifiles, Controls, ActnList;

type
  TLBLanguage = class(TComponent)
  private
    FIniFileName:String;
    ini     :TIniFile;
    fm      :TForm;
    FSaveDBinfo:Boolean;
    FSaveTBinfo:Boolean;
    FSaveListinfo:Boolean;
    Procedure LoadCaption(c:TButton);overload;
    Procedure LoadCaption(c:TRadioGroup);overload;
    Procedure LoadCaption(c:TListBox);overload;
    Procedure LoadCaption(c:TComboBox);overload;
    Procedure LoadCaption(c:TStringGrid);overload;
    Procedure LoadCaption(c:TStatusBar);overload;
    Procedure LoadCaption(c:TLabeledEdit);overload;
    Procedure LoadCaption(c:TListView);overload;
    Procedure LoadCaption(c:TTabControl);overload;
    Procedure LoadCaption(c:TPageControl);overload;
    Procedure LoadCaption(c:THeaderControl);overload;
    Procedure LoadCaption(c:TToolBar);overload;
    Procedure LoadCaption(c:TADOConnection);overload;
    Procedure LoadCaption(c:TADOCommand);overload;
    Procedure LoadCaption(c:TADODataSet);overload;
    Procedure LoadCaption(c:TADOQuery);overload;
    Procedure LoadCaption(c:TADOTable);overload;
    Procedure LoadCaption(c:TDBGrid);overload;
    Procedure LoadCaption(c:TMainMenu);overload;
    Procedure LoadCaption(c:TMenuItem);overload;
    Procedure LoadCaption(c:TAction);overload;
  protected
    { Protected declarations }
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Loaded; override;
  published
    property SaveTBinfo:Boolean read FSaveTBinfo write FSaveTBinfo;
    property SaveDBinfo:Boolean read FSaveDBinfo write FSaveDBinfo;
    property SaveListinfo:Boolean read FSaveListinfo write FSaveListinfo;
    property IniName: String read FIniFileName write FIniFileName;
  end;
  
implementation

{ TLBLanguage }

constructor TLBLanguage.Create(AOwner: TComponent);
var
  i       :Integer;
  s       :String;
begin
  inherited;
  if csDesigning in ComponentState then exit;
  fm:=TForm(Aowner);
  if FiniFileName = '' then FIniFileName := ChangeFileExt(Application.ExeName,'.Ini');
  ini:=TIniFile.Create(FIniFileName);
  s:=ini.ReadString(fm.Name,'Caption','');
  if s='' then ini.WriteString(fm.Name,'Caption',fm.Caption) else fm.Caption:=s;
  for i:=0 to fm.ComponentCount - 1 do
  begin
    if ((fm.Components[i] is TLabel)
       or (fm.Components[i] is TButton)
       or (fm.Components[i] is TCheckBox)
       or (fm.Components[i] is TDBCheckBox)
       or (fm.Components[i] is TRadioButton)
       or (fm.Components[i] is TBitBtn)
       or (fm.Components[i] is TSpeedButton)
       or (fm.Components[i] is TStaticText)
       or (fm.Components[i] is TGroupBox)
       or (fm.Components[i] is TPanel)) then LoadCaption(TButton(fm.Components[i]))
    else if (fm.Components[i] is TLabeledEdit) then LoadCaption(TLabeledEdit(fm.Components[i]))
    else if ((fm.Components[i] is TRadioGroup)
      or (fm.Components[i] is TDBRadioGroup)) then LoadCaption(TRadioGroup(fm.Components[i]))
    else if ((fm.Components[i] is TListBox)
      or (fm.Components[i] is TDBListBox)
      or (fm.Components[i] is TCheckListBox)) then LoadCaption(TListBox(fm.Components[i]))
    else if ((fm.Components[i] is TComboBox)
      or (fm.Components[i] is TDBComboBox)) then LoadCaption(TComboBox(fm.Components[i]))
    else if ((fm.Components[i] is TStringGrid)) then LoadCaption(TStringGrid(fm.Components[i]))
    else if ((fm.Components[i] is TStatusBar)) then LoadCaption(TStatusBar(fm.Components[i]))
    else if ((fm.Components[i] is TListView)) then LoadCaption(TListView(fm.Components[i]))
    else if ((fm.Components[i] is TTabControl)) then LoadCaption(TTabControl(fm.Components[i]))
    else if ((fm.Components[i] is TPageControl)) then LoadCaption(TPageControl(fm.Components[i]))
    else if ((fm.Components[i] is THeaderControl)) then LoadCaption(THeaderControl(fm.Components[i]))
    else if ((fm.Components[i] is TToolBar)) then LoadCaption(TToolBar(fm.Components[i]))
    else if ((fm.Components[i] is TADOConnection)) then LoadCaption(TADOConnection(fm.Components[i]))
    else if ((fm.Components[i] is TADOCommand)) then LoadCaption(TADOCommand(fm.Components[i]))
    else if ((fm.Components[i] is TADODataSet)) then LoadCaption(TADODataSet(fm.Components[i]))
    else if ((fm.Components[i] is TADOQuery)) then LoadCaption(TADOQuery(fm.Components[i]))
    else if ((fm.Components[i] is TADOTable)) then LoadCaption(TADOTable(fm.Components[i]))
    else if ((fm.Components[i] is TDBGrid)) then LoadCaption(TDBGrid(fm.Components[i]))
    else if ((fm.Components[i] is TMainMenu))
         or ((fm.Components[i] is TMenuItem)) then LoadCaption(TMenuItem(fm.Components[i]))
    else if ((fm.Components[i] is TAction)) then LoadCaption(TAction(fm.Components[i]))
    ;
  end;
  ini.Free;
  application.ProcessMessages;
end;

destructor TLBLanguage.Destroy;
begin
  inherited;
end;

procedure TLBLanguage.LoadCaption(c: TButton);
var
  n,s:String;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then ini.WriteString(n,c.name,c.Caption) else c.Caption := s;
end;

procedure TLBLanguage.LoadCaption(c: TLabeledEdit);
var
  n,s:String;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then ini.WriteString(n,c.name,c.EditLabel.Caption) else c.EditLabel.Caption := s;
end;

procedure TLBLanguage.LoadCaption(c: TListView);
var
  n,s:String;
  l  :TStrings;
  i  :Integer;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then
  begin
    l:=TStringList.Create;
    for i:=0 to c.Columns.Count -1 do
      l.Add(c.Columns[i].Caption);
    ini.WriteString(n,c.name,l.CommaText);
    l.Free;
  end
  else
  begin
    l:=TStringList.Create;
    l.CommaText := s;
    for i:=0 to c.Columns.Count -1 do
      c.Columns[i].Caption := l.Strings[i];
    l.Free;
  end;
end;


procedure TLBLanguage.LoadCaption(c: TListBox);
var
  n,s:String;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then  ini.WriteString(n,c.name,c.Items.CommaText) else c.Items.CommaText := s;
end;

procedure TLBLanguage.LoadCaption(c: TRadioGroup);
var
  n,s:String;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then ini.WriteString(n,c.name,c.Caption) else c.Caption := s;
  s:=ini.ReadString(n,c.Name+'Items','');
  if (s='') then ini.WriteString(n,c.name+'Items',c.Items.CommaText) else c.Items.CommaText := s;
end;

procedure TLBLanguage.LoadCaption(c: TComboBox);
var
  n,s:String;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then  ini.WriteString(n,c.name,c.Items.CommaText) else c.Items.CommaText := s;
end;

procedure TLBLanguage.LoadCaption(c: TStringGrid);
var
  n,s:String;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then ini.WriteString(n,c.name,c.Rows[0].CommaText) else c.Rows[0].CommaText := s;
end;

procedure TLBLanguage.LoadCaption(c: TStatusBar);
var
  n,s:String;
  l  :TStrings;
  i  :Integer;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then
  begin
    l:=TStringList.Create;
    for i:=0 to c.Panels.Count-1 do
      l.Add(c.Panels.Items[i].Text);
    ini.WriteString(n,c.name,l.CommaText);
    l.Free;
  end
  else
  begin
    l:=TStringList.Create;
    l.CommaText := s;
    for i:=0 to c.Panels.Count-1 do
      c.Panels.Items[i].Text:=l.Strings[i];
    l.Free;
  end;
end;

procedure TLBLanguage.LoadCaption(c: TTabControl);
var
  n,s:String;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then ini.WriteString(n,c.name,c.Tabs.CommaText) else c.Tabs.CommaText := s;
end;

procedure TLBLanguage.LoadCaption(c: TPageControl);
var
  n,s:String;
  l  :TStrings;
  i  :Integer;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then
  begin
    l:=TStringList.Create;
    for i:=0 to c.PageCount- 1 do
      l.Add(c.Pages[i].Caption);
    ini.WriteString(n,c.name,l.CommaText);
    l.Free;
  end
  else
  begin
    l:=TStringList.Create;
    l.CommaText := s;
    for i:=0 to c.PageCount- 1 do
      c.Pages[i].Caption:=l.Strings[i];
    l.Free;
  end;
end;

procedure TLBLanguage.LoadCaption(c: THeaderControl);
var
  n,s:String;
  l  :TStrings;
  i  :Integer;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then
  begin
    l:=TStringList.Create;
    for i:=0 to c.Sections.Count - 1 do
      l.Add(c.Sections[i].Text);
    ini.WriteString(n,c.name,l.CommaText);
    l.Free;
  end
  else
  begin
    l:=TStringList.Create;
    l.CommaText := s;
    for i:=0 to c.Sections.Count - 1 do
      c.Sections[i].Text:=l.Strings[i];
    l.Free;
  end;
end;

procedure TLBLanguage.LoadCaption(c: TToolBar);
var
  n,s:String;
  l  :TStrings;
  i  :Integer;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then
  begin
    l:=TStringList.Create;
    for i:=0 to c.ButtonCount - 1 do
      l.Add(c.Buttons[i].Caption);
    ini.WriteString(n,c.name,l.CommaText);
    l.Free;
  end
  else
  begin
    l:=TStringList.Create;
    l.CommaText := s;
    for i:=0 to c.ButtonCount - 1 do
      c.Buttons[i].Caption:=l.Strings[i];
    l.Free;
  end;
end;

procedure TLBLanguage.LoadCaption(c: TADOConnection);
var
  n,s:String;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then ini.WriteString(n,c.name,c.ConnectionString) else c.ConnectionString := s;
end;

procedure TLBLanguage.LoadCaption(c: TADOCommand);
var
  n,s:String;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then ini.WriteString(n,c.name,c.CommandText) else c.CommandText := s;
end;

procedure TLBLanguage.LoadCaption(c: TADODataSet);
var
  n,s:String;
  l  :TStrings;
  i  :Integer;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then ini.WriteString(n,c.name,c.CommandText) else c.CommandText := s;
  s:=ini.ReadString(n,c.Name+'Fields','');
  if (s='') then
  begin
    l:=TStringList.Create;
    for i:=0 to c.FieldCount - 1 do
      l.Add(c.Fields[i].DisplayLabel);
    ini.WriteString(n,c.Name+'Fields',l.CommaText);
    l.Free;
  end
  else
  begin
    l:=TStringList.Create;
    l.CommaText := s;
    for i:=0 to c.FieldCount - 1 do
      c.Fields[i].DisplayLabel:=l.Strings[i];
    l.Free;
  end;
end;

procedure TLBLanguage.LoadCaption(c: TADOQuery);
var
  n,s:String;
  l  :TStrings;
  i  :Integer;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then ini.WriteString(n,c.name,c.SQL.CommaText) else c.SQL.CommaText:= s;
  s:=ini.ReadString(n,c.Name+'Fields','');
  if (s='') then
  begin
    l:=TStringList.Create;
    for i:=0 to c.FieldCount - 1 do
      l.Add(c.Fields[i].DisplayLabel);
    ini.WriteString(n,c.Name+'Fields',l.CommaText);
    l.Free;
  end
  else
  begin
    l:=TStringList.Create;
    l.CommaText := s;
    for i:=0 to c.FieldCount - 1 do
      c.Fields[i].DisplayLabel:=l.Strings[i];
    l.Free;
  end;
end;

procedure TLBLanguage.LoadCaption(c: TADOTable);
var
  n,s:String;
  l  :TStrings;
  i  :Integer;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then ini.WriteString(n,c.name,c.TableName) else c.TableName:= s;
  s:=ini.ReadString(n,c.Name+'Fields','');
  if (s='') then
  begin
    l:=TStringList.Create;
    for i:=0 to c.FieldCount - 1 do
      l.Add(c.Fields[i].DisplayLabel);
    ini.WriteString(n,c.Name+'Fields',l.CommaText);
    l.Free;
  end
  else
  begin
    l:=TStringList.Create;
    l.CommaText := s;
    for i:=0 to c.FieldCount - 1 do
      c.Fields[i].DisplayLabel:=l.Strings[i];
    l.Free;
  end;
end;

procedure TLBLanguage.LoadCaption(c: TDBGrid);
var
  n,s:String;
  l  :TStrings;
  i  :Integer;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name+'Fields','');
  if (s='') then
  begin
    l:=TStringList.Create;
    for i:=0 to c.Columns.Count - 1 do
      l.Add(c.Columns[i].Title.Caption);
    ini.WriteString(n,c.Name+'Fields',l.CommaText);
    l.Free;
  end
  else
  begin
    l:=TStringList.Create;
    l.CommaText := s;
    for i:=0 to c.Columns.Count - 1 do
      c.Columns[i].Title.Caption :=l.Strings[i];
    l.Free;
  end;
end;

procedure TLBLanguage.LoadCaption(c: TMainMenu);
var
  n,s:String;
  l  :TStrings;
  i  :Integer;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then
  begin
    l:=TStringList.Create;
    for i:=0 to c.Items.Count - 1 do
    begin
      l.Add(c.Items[i].Caption);
    end;
    ini.WriteString(n,c.name,l.CommaText);
    l.Free;
  end
  else
  begin
    l:=TStringList.Create;
    l.CommaText := s;
    for i:=0 to c.Items.Count - 1 do
    begin
      c.Items[i].Caption:=l.Strings[i];
    end;
    l.Free;
  end;
end;

procedure TLBLanguage.LoadCaption(c: TMenuItem);
var
  n,s:String;
  l  :TStrings;
  i  :Integer;
begin
  if c.Count < 1 then exit;
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then
  begin
    l:=TStringList.Create;
    for i:=0 to c.Count - 1 do
    begin
      l.Add(c.Items[i].Caption);
    end;
    ini.WriteString(n,c.name,l.CommaText);
    l.Free;
  end
  else
  begin
    l:=TStringList.Create;
    l.CommaText := s;
    for i:=0 to c.Count - 1 do
    begin
      c.Items[i].Caption:=l.Strings[i];
    end;
    l.Free;
  end;
end;

Procedure TLBLanguage.LoadCaption(c:TAction);
var
  n,s:String;
begin
  n:=fm.Name;
  s:=ini.ReadString(n,c.Name,'');
  if (s='') then ini.WriteString(n,c.name,c.Caption) else c.Caption := s;
end;

procedure TLBLanguage.Loaded;
begin
  inherited;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -