![]() |
Gethtml in einem Delphi Thread?
Zitat:
und kann ich die funktion überhaupt darein tun weil ich schon was mit fehlern wegen irgend welchen sachen die da nicht kompatiobel sind usw? [edit=alcaeus]Delphi-Tags eingefuegt. Bitte in Zukunft selbst machen, Danke. Mfg, alcaeus[/edit] |
Re: Gethtml in einem Delphi Thread?
du machst dir das Leben reichlich schwer. Probier es mal damit:
Delphi-Quellcode:
nicht vergessen:
function getHTML(const url: string):string;
var idhttp :Tidhttp; begin idhttp :=Tidhttp.Create(Form1); result :=idhttp.Get(url); idhttp.Free; end;
Delphi-Quellcode:
einfach oben ergänzen *fg*
uses IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP; Warum sollte man das nicht in Threads ausführen können? Probier's doch einfach aus! |
Re: Gethtml in einem Delphi Thread?
und wo bekomme ich die komponenten her?
|
Re: Gethtml in einem Delphi Thread?
Zitat:
Also eigentlich ist die immer vorinstalliert und bei Delphi direkt dabei. Schau einfach mal unter "Indy clients" Anosnsten: ![]() |
Re: Gethtml in einem Delphi Thread?
Zitat:
Delphi-Quellcode:
unit UDemo2;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; TMyThread = class(TThread) private FMemoHandle : THandle; FUrl : String; protected procedure Execute; override; public constructor Create(MemoHandle: THandle; AUrl: String); end; var Form1: TForm1; implementation {$R *.dfm} uses WinInet; Function GetHTML(AUrl: string): string; var databuffer : array[0..4095] of char; ResStr : string; hSession, hfile, hRequest: hInternet; dwindex,dwcodelen,datalen,dwread,dwNumber: cardinal; dwcode : array[1..20] of char; res : pchar; Str : pchar; begin ResStr:=''; if pos('http://',lowercase(AUrl))=0 then AUrl:='http://'+AUrl; hSession:=InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); if assigned(hsession) then begin hfile:=InternetOpenUrl( hsession, pchar(AUrl), nil, 0, INTERNET_FLAG_RELOAD, 0); dwIndex := 0; dwCodeLen := 10; HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex); res := pchar(@dwcode); dwNumber := sizeof(databuffer)-1; if (res ='200') or (res ='302') then begin while (InternetReadfile(hfile, @databuffer, dwNumber, DwRead)) do begin if dwRead =0 then break; databuffer[dwread]:=#0; Str := pchar(@databuffer); resStr := resStr + Str; end; end else ResStr := 'Status:'+res; if assigned(hfile) then InternetCloseHandle(hfile); end; InternetCloseHandle(hsession); Result := resStr; end; constructor TMyThread.Create(MemoHandle: THandle; AUrl: String); begin FMemoHandle := MemoHandle; FUrl:= AUrl; FreeOnTerminate := True; inherited Create(True); end; procedure TMyThread.Execute; begin inherited; SendMessage(FMemoHandle, WM_SETTEXT, 0, Integer(@GetHTML(FUrl)[1])); end; procedure TermThread; begin Form1.Button1.Enabled := True; end; procedure TForm1.Button1Click(Sender: TObject); var thGetHTML : TMyThread; begin Button1.Enabled := False; thGetHTML := TMyThread.Create(Memo1.Handle, 'www.delphipraxis.net'); with thGetHTML do begin @OnTerminate := @TermThread; Suspended := False; end; end; end. |
Re: Gethtml in einem Delphi Thread?
Delphi-Quellcode:
Warum so umständlich? Warum übergibst du nicht eine Variable vom Typ TStrings, dann kannst du es in ein TMemo, ein TRichEdit oder in eine TStringListe laden, je nach belieben wie du willst.
procedure TMyThread.Execute;
begin inherited; SendMessage(FMemoHandle, WM_SETTEXT, 0, Integer(@GetHTML(FUrl)[1])); end; Desweiteren greifst du auf ein VCL Kontroll außerhalb einer Synchronize Methode zu, was potentiel gefährlich ist. Nicht umsonst schreibt der Assistent in jede neue TThread Unit:
Delphi-Quellcode:
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure TTest.UpdateCaption; begin Form1.Caption := 'Updated in a thread'; end; } |
Re: Gethtml in einem Delphi Thread?
Moin moin,
Zitat:
|
Re: Gethtml in einem Delphi Thread?
Ich nehme mal an, dass er wohl ein TMemo aubenutzt. Du benutzt zwar keine VCL methode, um in das Memo zuschreiben, erstmal nicht, aber wie kommt denn das TMemo zu seinen Lines? Doch wohl über eine VCL Methode.
|
Re: Gethtml in einem Delphi Thread?
Zitat:
nicht zu Problemen führen... (Nach meinem Wissensstand ist SendMessage Thread sicher, ich lasse mich aber auch eines besseren belehren) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:17 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz