Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#6

AW: HTML einer URL ohne TWebBrowser und Indys

  Alt 15. Nov 2010, 19:58
ich hätte hier noch eine Version die kein Problem mit Unicode hat.
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation
uses ExtActns;
{$R *.dfm}
Function GetTempDir:String;
var
p:Pchar;
begin
  p:=stralloc(255);
  GetTempPath(255,p);
  Result:=p;
  strdispose(p);
end;

Function MakeSaveURL(const AURL:String):String;
begin
  if Pos('http',LowerCase(AURL))=0 then Result := 'http://' +AURL else Result := AURL;
end;


function DownloadURLToFile(const AURL, AFileName : TFileName) : boolean;
begin
  Result:=True;

  with TDownLoadURL.Create(nil) do
  try
    URL := MakeSaveURL(AURL);
    Filename := AFileName;
    try
      ExecuteTarget(nil);
    except
      Result:=False;
    end;
  finally
    Free;
  end;
end;


Function GetURLContentAsString(const AURL:String;Var OK:Boolean):String;
var
  sl:TStringList;
  tmpf:String;
begin
  sl:=TStringList.Create;
  OK := false;
  try
  tmpf := IncludeTrailingBackSlash(gettempdir) + FormatDateTime('~hh_zzz',now) + '.tmp';
  if DownloadURLToFile(AURL,tmpf) then
    begin
       sl.LoadFromFile(tmpf);
       deletefile(PChar(tmpf));
       Result := sl.Text;
       ok := true;
    end;
  finally
   sl.Free;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  b:Boolean;
begin
    Memo1.Text := GetURLContentAsString('http://twitter.com/#!/bummi_w',b);
end;

end.
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat