Get a web page content without freeze in lazarus/freepsacal lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- ojZim · 2013-01-26 19:11 Hello  I have a problem! I added synapse componet to my project, and it's working very good:  Code: [Select]uses httpsend; function GetWebPageContent(const Url: string): String; var fs: TStringList; HTTP: THTTPSend; begin    fs := TStringList.Create;    HTTP := THTTPSend.Create;    try       HTTP.HTTPMethod('GET', Url);       fs.LoadFromStream(Http.Document);       Result := fs.Text;    finally       fs.Free;       http.Free;    end; end; procedure TForm1.Button1Click(Sender: TObject); begin   Memo1.Lines.Add(GetWebPageContent('http://www.iran.ir/')); end;  But i have a small problem! When I click on Button1, the program is freezing and i can't do action in my program! I want to use many procedures! like this: Code: [Select]procedure OnGetWebFinished(Header: String; Document: String); begin end; My English is very bad, sorry for my bad English Thanks. I waiting for my Answer! ---------------------------------------------------------------------- wjackson153 · 2013-01-26 20:04 Have you tried adding the following: application.processmessages; ---------------------------------------------------------------------- Leledumbo · 2013-01-26 20:05 Synapse is purely object oriented (and mostly synchronous), use lNet if you want even driven networking library. If you want to stick to Synapse, use threads and Synchronize() at the end of Execute(). QuoteHave you tried adding the following: application.processmessages; That won't work, it's Synapse that's blocking, not the application code. ---------------------------------------------------------------------- ojZim · 2013-01-26 20:29 Quote from: wjackson153 on January 26, 2013, 09:04:21 pmHave you tried adding the following: application.processmessages; Thank for your answer! No it's not solve my problem! Thanks. Quote from: Leledumbo on January 26, 2013, 09:05:44 pmSynapse is purely object oriented (and mostly synchronous), use lNet if you want even driven networking library. If you want to stick to Synapse, use threads and Synchronize() at the end of Execute(). Thanks for your answer! Is lNet componet works on linux? if it's working on linux i use it!! But if i want to stock to Synaspe, How can i use threads and Synchronize() at the end of Execute()? I waiting for your answers! Thanks! ---------------------------------------------------------------------- wjackson153 · 2013-01-26 20:46 For linux I would use  a simpler method Combine Tprocess with wget  See my example on wiki http://wiki.lazarus.freepascal.org/Executing_External_Programs#A_Simpl e_Example ---------------------------------------------------------------------- Silvio Clécio · 2013-01-26 21:28 Try it buddy: Code: [Select]uses   fphttpclient; procedure ProcessContent; begin   with TFPHTTPClient.Create(nil) do   try     Form1.Memo1.Text := Get(         'http://www.lazarus.freepascal.org/index.php/topic,19685.msg11 2286.html');   finally     Free;   end; end; procedure TForm1.Button1Click(Sender: TObject); begin   BeginThread(TThreadFunc(@ProcessContent)); end; ---------------------------------------------------------------------- ojZim · 2013-01-26 21:57 Quote from: silvioprog on January 26, 2013, 10:28:50 pmTry it buddy: Code: [Select]uses   fphttpclient; procedure ProcessContent; begin   with TFPHTTPClient.Create(nil) do   try     Form1.Memo1.Text := Get(         'http://www.lazarus.freepascal.org/index.php/topic,19685.msg11 2286.html');   finally     Free;   end; end; procedure TForm1.Button1Click(Sender: TObject); begin   BeginThread(TThreadFunc(@ProcessContent)); end; WoW! THanks for your Answer! just BeginThread(TThreadFunc(@ProcessContent)); working good, my Problem is solved by your help! the BeginThread(TThreadFunc(@ProcessContent)); is solved my problem. thank you! ---------------------------------------------------------------------- Leledumbo · 2013-01-27 06:11 QuoteThanks for your answer! Is lNet componet works on linux? if it's working on linux i use it!!Yes, lNet works on many platforms. QuoteBut if i want to stock to Synaspe, How can i use threads and Synchronize() at the end of Execute()?You can use Silvio's answer, but he uses the built-in (FCL) fphttpclient, which is great as well. Changing to Synapse should be easy, just change the ProcessContent method. ---------------------------------------------------------------------- ojZim · 2013-01-29 12:20 Quote from: Leledumbo on January 27, 2013, 07:11:13 amQuoteThanks for your answer! Is lNet componet works on linux? if it's working on linux i use it!!Yes, lNet works on many platforms. QuoteBut if i want to stock to Synaspe, How can i use threads and Synchronize() at the end of Execute()?You can use Silvio's answer, but he uses the built-in (FCL) fphttpclient, which is great as well. Changing to Synapse should be easy, just change the ProcessContent method. Yes Thank you! I used from Silvio's answer and i changed fphttpclient to Synapse. It was easily. And my code is: Code: [Select]uses httpsend; function GetWebPageContent(const Url: string): String; var fs: TStringList; HTTP: THTTPSend; begin    fs := TStringList.Create;    HTTP := THTTPSend.Create;    try       HTTP.HTTPMethod('GET', Url);       fs.LoadFromStream(Http.Document);       Result := fs.Text;    finally       fs.Free;       HTTP.Free;    end; end; procedure aa(); begin   Form1.Memo1.Lines.Add(GetWebPageContent('http://www.iran.ir/')); end; procedure TForm1.Button1Click(Sender: TObject); begin   BeginThread(TThreadFunc(@aa)); end; Now it's not freezing and working good! Thank from all.