Hello, experts! Hello, I have never worked with threads, but a task has appeared for which we need threads.

Actually, I have a list of sites, there is a procedure that makes the request a parsit request, what I need, writes to a variable. Actually how to do this using threads? Below is a complete listing of the example, what the program is doing now, I repeat, this is only an example.

Thanks in advance!

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls; type TForm1 = class(TForm) Button1: TButton; IdHTTP1: TIdHTTP; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure pars(s1,s2,s3,s4,s5:string); private { Private declarations } public { Public declarations } end; type sp1=record title:string[150]; purl:string[200]; end; var Form1: TForm1; i,n,t:integer; title,rss,html,title1,title2:WideString; mas,mas1,mas2,mas3:array[1..50]of sp1; implementation {$R *.dfm} procedure TForm1.pars(s1,s2,s3,s4,s5:string); var i,n:integer; begin rss:=IdHTTP1.Get(s1); n:=1; i:=1; title:=''; while (i<=length(rss)) do begin if pos(s2,rss)<>0 then begin Delete(rss,1,pos(s2,rss)+length(s2)-1); title:=copy(rss,1,pos(s3,rss)-1); memo1.lines.add(title); mas[n].title:=title; Delete(rss,1,pos(s4,rss)+length(s4)-1); title:=copy(rss,1,pos(s5,rss)-1); memo1.lines.add(title); mas[n].purl:=title; n:=n+1; Application.ProcessMessages(); end else break; end; inc(i); Application.ProcessMessages(); end; procedure TForm1.Button1Click(Sender: TObject); begin pars('http://filmix.net/',''' title=''',''' /></a>','<a href="','">смотреть онлайн »'); mas1:=mas; pars('http://bigcinema.tv/','</span></li></ul></div><div class="topic_info"><h2 class="title">','</h2>','<!-- / tag groups--><a href="','" class="watch" title="'); mas2:=mas; end; 

end.

    1 answer 1

    Create a new thread. (In the menu, press new below others and look for the Thread object ) Copy the body of the pars procedure into the thread's execute procedure. When you need to create a new thread in the code (the threadobject that you created will be an object. Then you declare a variable whose type will be your object. ( var x:TThreadObject; ) )