zoukankan      html  css  js  c++  java
  • delphi inifile 支持 utf8

    Uses IniFiles;
    
    const
      SZ_APP_NAME = 'demo_test';
    
    Procedure TForm1.GetSettings;
    var
      _MemIniU: TMemIniFile;
      _SettingsPath: string;
    begin
      try
        _SettingsPath := GetHomePath + PathDelim + SZ_APP_NAME + PathDelim;
        if ForceDirectories(_SettingsPath) then
        begin
          _MemIniU := TMemIniFile.Create(ChangeFileExt(_SettingsPath,
            'Settings.ini'), TEncoding.UTF8);
          try
            if _MemIniU.ReadInteger(SZ_APP_NAME, 'WindowLeft', -1) = -1 then
              Form1.Position := poScreenCenter
            else
            begin
              Form1.Left := _MemIniU.ReadInteger(SZ_APP_NAME, 'WindowLeft', 10);
              Form1.Top := _MemIniU.ReadInteger(SZ_APP_NAME, 'WindowTop', 10);
              Form1.Width := _MemIniU.ReadInteger(SZ_APP_NAME, 'WindowWidth', 594);
              Form1.Height := _MemIniU.ReadInteger(SZ_APP_NAME,
                'WindowHeight', 342);
            end;
              Edit1.Text := _MemIniU.ReadString(SZ_APP_NAME, 'UnicodeText', 'ąčę');
          finally
            _MemIniU.Free;
          end;
        end;
      except
        on E: Exception do
          MessageDlg(PWideChar(E.Message), TMsgDlgType.mtError,
            [TMsgDlgBtn.mbOK], 0);
      end;
    end;
    
    Procedure TForm1.SaveSettings;
    var
      _MemIniU: TMemIniFile;
      _SettingsPath: string;
    begin
      try
        _SettingsPath := GetHomePath + PathDelim + SZ_APP_NAME + PathDelim;
        _MemIniU := TMemIniFile.Create(ChangeFileExt(_SettingsPath, 'Settings.ini'),
          TEncoding.UTF8);
        try
          if Form1.WindowState <> TWindowState.wsMaximized then
          begin
            _MemIniU.WriteInteger(SZ_APP_NAME, 'WindowLeft', Form1.Left);
            _MemIniU.WriteInteger(SZ_APP_NAME, 'WindowTop', Form1.Top);
            _MemIniU.WriteInteger(SZ_APP_NAME, 'WindowWidth', Form1.Width);
            _MemIniU.WriteInteger(SZ_APP_NAME, 'WindowHeight', Form1.Height);
            _MemIniU.WriteString(SZ_APP_NAME, 'UnicodeText', Edit1.Text);
          end;
          _MemIniU.UpdateFile;
        finally
          _MemIniU.Free;
        end;
      except
        on E: Exception do
          MessageDlg(PWideChar(E.Message), TMsgDlgType.mtError,
            [TMsgDlgBtn.mbOK], 0);
      end;
    end;
    

      

  • 相关阅读:
    在泛型方法中返回泛型数组
    java泛型方法返回泛型结果
    hive -e和hive -f的区别(转)
    hive表批处理
    python网络编程——实现简单聊天
    python网络编程(转)
    python分布式编程(转)
    shell多线程之进程间通信(3)
    在xml文件中使用该控件
    Java文件中代码
  • 原文地址:https://www.cnblogs.com/starluck/p/6611550.html
Copyright © 2011-2022 走看看