AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein ini file , readstring UTF vs. ASCII
Thema durchsuchen
Ansicht
Themen-Optionen

ini file , readstring UTF vs. ASCII

Ein Thema von bernhard_LA · begonnen am 26. Jul 2021 · letzter Beitrag vom 12. Okt 2021
Antwort Antwort
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.123 Beiträge
 
Delphi 11 Alexandria
 
#1

ini file , readstring UTF vs. ASCII

  Alt 26. Jul 2021, 22:41
bin mit dem Code unten gerade ziemlich aufgelaufen,
auf einem PC und einer ini Datei im UTF-8 Format lief der code ins leere,
erst nachdem ich das Format der DAtei auf ASCII umgestellt habe gings,
ist diese Problem bekannt ???




Delphi-Quellcode:

var
  IniFile: TIniFile;
begin

  if FileExists(filename) then
  begin
    IniFile := TIniFile.Create(filename);
    try
      Result := IniFile.ReadString(SectionStr, IdentStr, '<none>');
    finally
      IniFile.Free;
    end;
  end
  else
  begin
    Result := '<no file found>';
  end;
  Mit Zitat antworten Zitat
Benutzerbild von Dalai
Dalai

Registriert seit: 9. Apr 2006
1.680 Beiträge
 
Delphi 5 Professional
 
#2

AW: ini file , readstring UTF vs. ASCII

  Alt 26. Jul 2021, 22:51
Hat(te) die Datei vielleicht einen BOM (Byte Order Mark)? Wenn ja, ist das wahrscheinlich keine offiziell unterstützte Geschichte, denn die INI-Funktionen von Windows können nur ANSI und UTF-16.

Grüße
Dalai
  Mit Zitat antworten Zitat
venice2
(Gast)

n/a Beiträge
 
#3

AW: ini file , readstring UTF vs. ASCII

  Alt 26. Jul 2021, 22:53
Ist doch kein Fehler oder?
Ini Files unterstützt kein Unicode.

Dir wird also nichts anderes übrigbleiben zu prüfen in welchem Format die INI geschrieben wurde.
Und dann entsprechend Utf8ToString verwenden.

Oder Versuchs mal mit TMemIniFile
  Mit Zitat antworten Zitat
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.123 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: ini file , readstring UTF vs. ASCII

  Alt 26. Jul 2021, 23:03
geschrieben wurde mit einer anderen Delphi Anwendung ,
auch wieder alles mit der Klasse Inifile ......
auf einem anderen PC hat die Anwendung ohne Probleme funktioniert

meine aktuelle Zwischenlösung :
Datei mit Notepad öffnen und dann als ASCII Format abspeichern, dann scheint alles zu passen
  Mit Zitat antworten Zitat
venice2
(Gast)

n/a Beiträge
 
#5

AW: ini file , readstring UTF vs. ASCII

  Alt 26. Jul 2021, 23:15
Zitat:
geschrieben wurde mit einer anderen Delphi Anwendung ,
auch wieder alles mit der Klasse Inifile ......
Nein wohl eher mit der TMemIniFile denn nur diese unterstützt Utf8

Die Klasse TInifile ist ein Wrapper für die Windows API IniFiles und die kann nun mal nur EASCII (ANSI) und UTF-16.
So wie @Dalai schon sagte.

Geändert von venice2 (26. Jul 2021 um 23:19 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.149 Beiträge
 
Delphi 12 Athens
 
#6

AW: ini file , readstring UTF vs. ASCII

  Alt 27. Jul 2021, 03:04
Ini Files unterstützt kein Unicode.
Doch, tut es.

Aber eben nur UTF-16 ohne BOM.

TMemIniFiles von Delphi kann, wie eine TStringList, eben noch viel mehr, was aber die "offizielle" INI-API von Windows eben nicht "kann".


Wie beim XML gibt es hier eine automatische Erkennung durch die #0
quasi '[...' oder '['#0'...' am Anfang.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (27. Jul 2021 um 03:09 Uhr)
  Mit Zitat antworten Zitat
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.123 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: ini file , readstring UTF vs. ASCII

  Alt 12. Okt 2021, 08:48
a) wenn ich die Ini files Klasse weiterhin verwenden will, benötige ich einen Check auf BOM , ich habe diesen code hierzu gefunden https://www.delphi-treff.de/tipps-tr...rung-erkennen/
eine extra Zeile Code und eine Exception werfen wenn das BOM Flag gefunden wird ?


b) bei dieser Option , von https://docwiki.embarcadero.com/Code...niFile_(Delphi),
wie übergebe ich den Filenamen an meine Settingsklasse ?
Die Funktion OpenIniFileInstance() ist leider nicht erklärt


Delphi-Quellcode:

var
  SettingsFile : TCustomIniFile;
begin
  { Open an instance }
  SettingsFile := OpenIniFileInstance();

  try
    {
    Read all saved values from the last session. The section name
    is the name of the form. Also use the form's properties as defaults.
    }

    Top := SettingsFile.ReadInteger(Name, 'Top', Top );
    Left := SettingsFile.ReadInteger(Name, 'Left', Left );
    Width := SettingsFile.ReadInteger(Name, 'Width', Width );
    Height := SettingsFile.ReadInteger(Name, 'Height', Height );
    Caption := SettingsFile.ReadString (Name, 'Caption', Caption);

    { Load last window state. }
    case SettingsFile.ReadBool(Name, 'InitMax', WindowState = wsMaximized) of
      true : WindowState := wsMaximized;
      false: WindowState := wsNormal;
    end;

  finally
    SettingsFile.Free;
  end;
end;
PS : diesmal wurde die Datei mit dem Notepad++ erstellt

Geändert von bernhard_LA (12. Okt 2021 um 09:19 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.149 Beiträge
 
Delphi 12 Athens
 
#8

AW: ini file , readstring UTF vs. ASCII

  Alt 12. Okt 2021, 09:28
Erstmal, INI-Dateiteien der WinAPI gibt es ausschließlich in ANSI oder UTF-16 (ohne BOM).

Dein Problem dürfte sich aber durch die TStringList lösen lassen, also mit RadioGroup1.ItemIndex=2.


Zitat:
PS : diesmal wurde die Datei mit dem Notepad++ erstellt
Das darf man gern machen, aber beim Speichern wählt man dann gefälligst auch das richtige Format.

Zitat:
Check auf BOM
Da gibt es auch was von Ratiof TEncoding.

Zitat:
Die Funktion OpenIniFileInstance() ist leider nicht erklärt
Die ist doch selbsterklärend?
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (12. Okt 2021 um 09:33 Uhr)
  Mit Zitat antworten Zitat
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.123 Beiträge
 
Delphi 11 Alexandria
 
#9

AW: ini file , readstring UTF vs. ASCII

  Alt 12. Okt 2021, 12:10
nicht ganz, weil meiene naheliegende Lösung hier dann einen Abstract Fehler zurückliefert ....



Delphi-Quellcode:
  
var
  IniFile: TCustomIniFile;
  if FileExists(filename) then
  begin
    IniFile := TCustomIniFile.Create(filename);
    try
      Result := IniFile.ReadString(SectionStr, IdentStr, '<none>');
    finally
      IniFile.Free;
    end;
  end
  else
  begin
    Result := '<no file found>';
  end;
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#10

AW: ini file , readstring UTF vs. ASCII

  Alt 12. Okt 2021, 12:58
.. aus der Hilfe..
Zitat:
Note: Use TCustomIniFile as a base class when defining components that access ini files. Ini files are text files that are divided into sections with variable assignments in each section. TCustomIniFile introduces properties and methods to handle storage and retrieval of application-specific information and settings in a standard ini file.

..

Do not create instances of TCustomIniFile. Instead, use or create descendants of TCustomIniFile, such as TIniFile, TRegistryIniFile, and TMemIniFile
Grüße
Klaus
Klaus
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:53 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz