TINIFile使用FillSectionList过程读取和分析INI文件结构。在这个过程中,会检查该文件是否具备微软的UTF-8文件头(#$EF#$BB#$BF),如果有,则记录下来,并在保存的时候也同样添加这个文件头。 if (AStrings.Count > 0) and (copy(AStrings.Strings[0],1,Length(Utf8Bom)) = Utf8Bom) then begin FBOM := Utf8Bom; AStrings.Strings[0] := copy(AStrings.Strings[0],Length(Utf8Bom)+1,Length(AStrings.Strings[0])); end; 对不同数据类型Read和Write的方法,本质上都是调用ReadString和WriteString,比如 function TCustomIniFile.ReadInteger(const Section, Ident: string; Default: Longint): Longint; begin // StrToInfDef() supports hex numbers prefixed with '0x' via val() Result := StrToIntDef(ReadString(Section, Ident, ''), Default); end; 由于Lazarus基于UTF-8,因此如果不在代码中做特殊处理的话,Lazarus是按UTF-8编码读写INI文件的内容的,这会导致包括中文文本的INI文件读写出现异常。