Autor Beitrag
cyberbug
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 53

WIN XP

BeitragVerfasst: Di 04.11.08 20:11 
Hi,

ich nutze IdHttp1.Get(), um den Inhalt einer Textdatei, die auf meinem Webserver liegt, zu bekommen. Dieser Text wird anschliessend in eine Memo geschrieben.
ausblenden Delphi-Quelltext
1:
memText.Text := IdHttp1.Get('http://server.de/text.txt');					



Der Text dieser Textdatei liegt jedoch in Unicode(UTF8) vor. Wie bekomme ich den auch als solches in die Memo?(benutze delphi 2009)

MFG cyberbug
cyberbug Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 53

WIN XP

BeitragVerfasst: Mi 05.11.08 20:22 
Weiss niemand eine Lösung? Es ist mir wichtig... Oder fehlen noch Informationen?

MFG cyberbug
littleDave
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111
Erhaltene Danke: 2

Win 7
Delphi 7 Prof, Turbo Delphi, VS 2008 Team System, VS 2010 Premium
BeitragVerfasst: Mi 05.11.08 20:56 
Also mal einfach so aus dem Bauch heraus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure MakeUTF8String(pAnsi: PAnsiString; var pUTF8: Pointer);
begin
  pUTF8 := pAnsi; 
end;

procedure TForm1.Button1Click(Sender: TObject);
var Ansi : AnsiString;
    UF8  : PUTF8String;
begin
  // AnsiString von IdHTTP.Get bekommen
  Ansi := IdHttp1.Get('http://server.de/text.txt');
  // Compiler-Magic umgehen
  MakeUTF8String(@Ansi, UTF8);
  // UTF8 -> WideString
  memText.Text := UTF8Decode(UTF8^);
end;

Keine Ahnung, ob das funktioniert, einfach mal so aus dem Bauch heraus runtergeschrieben
cyberbug Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 53

WIN XP

BeitragVerfasst: Do 06.11.08 17:58 
Danke für die Antwort!

Es funktioniert allerdings nicht...
Folgende Fehler tauchen auf:

ausblenden Quelltext
1:
2:
3:
4:
5:
[DCC Warnung] u_Main.pas(206): W1058 Implizite String-Umwandlung mit potenziellem Datenverlust von 'string' zu 'AnsiString'
[DCC Fehler] u_Main.pas(208): E2035 Nicht genügend wirkliche Parameter
[DCC Warnung] u_Main.pas(210): W1000 Symbol 'UTF8Decode' ist veraltet : 'Use UTF8ToWideString or UTF8ToString'
[DCC Fehler] u_Main.pas(210): E2003 Undeklarierter Bezeichner: 'UTF8'
[DCC Fataler Fehler] Projekt.dpr(9): F2063 Verwendete Unit 'u_Main.pas' kann nicht compiliert werden


Folgender Code wurde genutzt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TFormMain.DownloadText();
var Ansi : AnsiString;
    UF8  : PUTF8String;
begin
  // AnsiString von IdHTTP.Get bekommen
  Ansi := IdHttp1.Get('http://server.de/text.txt');
  // Compiler-Magic umgehen
  MakeUTF8String(@Ansi, UTF8);
  // UTF8 -> WideString
  memText.Text := UTF8Decode(UTF8^);
  // blabla ;)
end;


MFG cyberbug


Zuletzt bearbeitet von cyberbug am Do 06.11.08 21:10, insgesamt 1-mal bearbeitet
littleDave
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111
Erhaltene Danke: 2

Win 7
Delphi 7 Prof, Turbo Delphi, VS 2008 Team System, VS 2010 Premium
BeitragVerfasst: Do 06.11.08 18:12 
Was für ein Datentyp bekommst du denn bei idHTTP.Get(...)? Ist es "AnsiString", "WideString" oder einfach nur "string"?

Mit den Fehlern: nenn mal die Varialbe nicht UF8 sonder UTF8 ;-)
cyberbug Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 53

WIN XP

BeitragVerfasst: Do 06.11.08 21:09 
Es ist ein String, jedenfalls vermute ich dass, aber ich möchte ja eig das UTF8 haben. Und als ich es umbenannt habe, waren noch immer Fehler da...

ausblenden Quelltext
1:
2:
3:
4:
5:
[DCC Warnung] u_Main.pas(206): W1058 Implizite String-Umwandlung mit potenziellem Datenverlust von 'string' zu 'AnsiString'
[DCC Fehler] u_Main.pas(208): E2033 Die Typen der tatsächlichen und formalen Var-Parameter müssen übereinstimmen
[DCC Warnung] u_Main.pas(210): W1000 Symbol 'UTF8Decode' ist veraltet : 'Use UTF8ToWideString or UTF8ToString'
[DCC Fehler] u_Main.pas(210): E2010 Inkompatible Typen: 'RawByteString' und 'PUTF8String'
[DCC Fataler Fehler] Projekt.dpr(9): F2063 Verwendete Unit 'u_Main.pas' kann nicht compiliert werden


Weiss noch jemand rat?

MFG cyberbug
littleDave
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111
Erhaltene Danke: 2

Win 7
Delphi 7 Prof, Turbo Delphi, VS 2008 Team System, VS 2010 Premium
BeitragVerfasst: Do 06.11.08 21:24 
Ich habs nochmal umgeschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var RawString  : string;
    UTF8String : PUTF8String;
begin
  RawString  := IdHTTP1.Get('http://server.de/text.txt');
  UTF8String := @Pointer(RawString);
  // Bis Delphi 2007
     Memo1.Text := UTF8Decode(UTF8String^);
  // Delphi 2009:
     Memo1.Text := UTF8ToString(UTF8String^);
end;
cyberbug Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 53

WIN XP

BeitragVerfasst: Do 06.11.08 21:33 
Juchu, die Errors sind weg, danke für deine Bemühungen ;)

MFG cyberbug