Hi,
I use the command 'CopyFile()', but i would like that my application does not have to wait until the copy has finished.
So I guess that I have to use it in a second thread, but how to do this?
I would also like to know how to parse a text (html) file in the background.
The following code is what I came up with, but I am unsure if this is the best way.
procedure TDownloadsongtextThread.ShowStatus;
begin
Form1.MemoLyrics.Lines.Add(flijn);
end;
procedure TDownloadsongtextThread.Execute;
var gevonden, goed: boolean;
lijn, templijn: string;
Filevar: textFile;
i: integer;
fs: TFilestream;
begin
gevonden:=false; goed:=false;
fs := TFileStream.Create(tempdir+Directoryseparator+'songtext.txt', fmOpenWrite or fmCreate);
try
goed:=HttpGetBinary(urlvar, fs);
finally
fs.Free;
end;
// Parsing Songtext form http://www.lyricsdepot.com/
if pos('http://www.lyricsdepot.com/',urlvar)>0 then
begin
if goed then
begin
AssignFile(Filevar,tempdir+Directoryseparator+'songtext.txt');
Reset(Filevar);
While not Terminated and not eof(filevar) and not gevonden do
begin
Readln(Filevar,lijn);
if pos('ringmatch();',lijn)>0 then
begin
Readln(Filevar,lijn); Readln(Filevar,lijn);
repeat
templijn:=Copy(lijn,1,pos('<br>',lijn)-1);
Delete(lijn,1,pos('<br>',lijn)+3);
flijn:=templijn;
Synchronize(@Showstatus);
until pos('<br>',lijn)<1;
if length(lijn)>1 then
begin
flijn:=lijn;
Synchronize(@Showstatus);
end;
gevonden:=true;
end;
end;
CloseFile(Filevar);
end;
end;
Working on Linux with Lazarus 1.1