Autor |
Beitrag |
LittleBen
Beiträge: 258
Erhaltene Danke: 4
Win 7, Mac OS
Delphi 7
|
Verfasst: Sa 04.01.14 18:24
Hallo,
obwohl man so viel zu diesem Problem findet, habe ich es immer noch nicht hinbekommen, dass Umlaute richtig dargestellt werden
Ich benutze Delphi 7 und Indy 10.
Habe so ziemlich alles probiert, was man hier so findet, aber nichts funktioniert
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8:
| var IdHTTP: TIdHTTP; begin IdHTTP:= TIdHTTP.Create(nil); try memo1.Text:= UTF8Decode(IdHTTP.Get('http://xenforo.com/community/threads/umlaut-test-%C3%B6%C3%A4%C3%BC%C3%9F.96/')); finally IdHTTP.Free; end; |
Weiß jemand, wie ich das zum Laufen bekomm?
Viele Grüße
Benny
|
|
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Sa 04.01.14 19:15
Glaubst Du ernsthaft, dass alles, was auf einer Webseite ist, in ein Memo geladen werden kann?
Das kommt dann so an:
Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
| <!DOCTYPE html> <html id="XenForo" lang="en-US" dir="LTR" class="Public LoggedOut NoSidebar Responsive" xmlns:fb="http://www.facebook.com/2008/fbml"> <head>
<meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <base href="http://xenforo.com/community/" /> <script> var _b = document.getElementsByTagName('base')[0], _bH = "http://xenforo.com/community/"; if (_b && _b.href != _bH) _b.href = _bH; </script>
<title>Umlaut Test: öäüß | XenForo Community</title> ... |
|
|
jaenicke
Beiträge: 19284
Erhaltene Danke: 1742
W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
|
Verfasst: Sa 04.01.14 19:59
Das ist doch genau sein Problem, wenn du in dein Ergebnis schaust, siehst du, dass die Umlaute kaputt sind...
Bei XE5 brauche ich kein UTF8Decode, da wird es einfach so korrekt angezeigt...
Ein Delphi 7 muss ich mal im virtuellen PC anschauen...
|
|
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Sa 04.01.14 20:25
Die Function UTF8Decode ergibt auch kein gutes Ergebnis.
Memo1.lines.add(UTF8Decode('Umlaut Test: öäüÃY | XenForo Community'));
Ergebnis
Umlaut Test: öäü_Y | XenForo Community
Richtig wäre:
Umlaut Test: öäüß
|
|
jaenicke
Beiträge: 19284
Erhaltene Danke: 1742
W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
|
Verfasst: Sa 04.01.14 20:34
So funktioniert es bei Delphi 7: Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
| var IdHttp: TIdHTTP; Test: TStringStream; begin IdHttp := TIdHTTP.Create(nil); try Test := TStringStream.Create(''); try IdHttp.Get('http://xenforo.com/community/threads/umlaut-test-%C3%B6%C3%A4%C3%BC%C3%9F.96/', Test); Test.Position := 0; Memo1.Text := StringReplace(Utf8Decode(Test.DataString), #10, #13#10, [rfReplaceAll]); finally Test.Free; end; finally IdHttp.Free; end; | Frag mich nicht warum, hab auch keine Lust zu suchen, dazu fehlt in Delphi 7 einfach zu viel Komfort.
Und wie schon geschrieben, bei XE5 kann ich das Ergebnis von Get einfach direkt ins Memo schreiben.
Für diesen Beitrag haben gedankt: LittleBen
|
|
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Sa 04.01.14 21:04
Funktioniert mit DELPHI 2009.
|
|
mandras
Beiträge: 430
Erhaltene Danke: 107
Win 10
Delphi 6 Prof, Delphi 10.4 Prof
|
Verfasst: Sa 04.01.14 21:43
Mit D6 und Indy 9.0.17 geht's auch.
|
|
LittleBen
Beiträge: 258
Erhaltene Danke: 4
Win 7, Mac OS
Delphi 7
|
Verfasst: So 05.01.14 02:48
Funktioniert, wenn ich einfach nur den Inhalt vom Stream nehme:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8:
| Stream:= TStringStream.Create(''); try FIdHttp.Get(AUrl, Stream); Stream.Position:= 0; Result:= Stream.DataString; finally Stream.Free; end; |
Die Funktion Utf8Decode liefert mir einen leeren String. Aber ich hab alles was ich brauche
Danke!
|
|
Martok
Beiträge: 3661
Erhaltene Danke: 604
Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
|
Verfasst: Mo 06.01.14 00:43
Moin!
Liest eigentlich nie jemand die Dokumentation (oder Quellcodes, hier: Funktionsheader)?
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| uses ..., idHTTP, idGlobal;
var IdHTTP: TIdHTTP; s: string; begin IdHTTP:= TIdHTTP.Create(nil); try s:= IdHTTP.Get('http://xenforo.com/community/threads/umlaut-test-%C3%B6%C3%A4%C3%BC%C3%9F.96/', TIdTextEncoding.UTF8); memo1.Text:= utf8decode(s); finally IdHTTP.Free; end; |
D7, Indy 10.5.
Warum die das nicht aus den HTTP-Headern lesen ist mir absolut unklar.
Deswegen jedenfalls funktioniert auch der Umweg über Streams: da wird keine Transformation gemacht.
jaenicke hat folgendes geschrieben : | Frag mich nicht warum, hab auch keine Lust zu suchen, dazu fehlt in Delphi 7 einfach zu viel Komfort. |
Really? Ctrl-Klick, Ctrl-Shift-Down?
jaenicke hat folgendes geschrieben : | Und wie schon geschrieben, bei XE5 kann ich das Ergebnis von Get einfach direkt ins Memo schreiben. |
Wenn ich raten müsste: weil Strings jetzt Charsets haben und die Konvertierung nicht mehr in Indy passiert sondern irgendwo anders.
Viele Grüße,
Sebastian
_________________ "The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
|
|