Delphi讀取utf8格式ini及取得動態內容

使用Delphi讀取utf8格式時需使用Tmeminifile,另外動態取得的範例。

VAR SYSINI: TMemIniFile; // 讀取utf8格式的ini需使用TMemIniFile
ts:tstringlist;
i:integer;
ApplicationPath:string;
begin
// 先取得目前執行路徑
ApplicationPath := ExtractFilePath(Application.exename);
if ApplicationPath[length(ApplicationPath)] = ‘\’ then
begin
ApplicationPath := copy(ApplicationPath, 1, length(ApplicationPath) – 1);
end;
// 讀取sys.ini裡的memberid區塊並顯示值
MEMO1.Lines.Clear;
ts:=tstringlist.Create;
SYSini := TMemIniFile.Create(ApplicationPath+’\sys.ini’,TEncoding.UTF8);
if NOT (SYSini = nil) then begin
sysini.ReadSection(‘memberid’,ts);
for I:=0 TO TS.Count-1 DO BEGIN
MEMO1.Lines.Add(TS[I]);
MEMO1.LINES.Add(sysini.ReadString(‘MEMBERID’,TS[I],”));
END;
end;
ts.Free;
end;