14. december 2002 - 03:03Der er
8 kommentarer og 1 løsning
Tråde + synchronize
Jeg har en tråd der kaldes fra Form1.
Meningen er den skal udregne nogle værdier for de filer der er i richedit2. Det virker fint nok, men form1 opdateres først når hele min tråd er færdig, meningen er at den skal opdatere hver gang doCRC er færdig. (en gang per linje i richedit2).
var filename, path, crc1, crc2, str:string; good,bad,missing,pathdelim : integer;
procedure CRCThread.doCRC(); begin filename:=copy(str,0,pos(' ',str)-1); crc1:=Lowercase(copy(str,pos(' ',str)+1,length(str))); if fileexists(path+filename) then begin crc2:=Lowercase(CRC.GetCRC32(path+filename)); if crc1<>crc2 then begin inc(bad); Form1.Richedit1.Lines.Add(str+' BAD'); Form1.Memo3.Lines[0]:=filename+'.BAD'; Form1.Memo3.Lines.SaveToFile(path+filename+'.BAD'); end else begin inc(good); end; end else begin inc(missing); Form1.Richedit1.Lines.Add(str+' MISSING'); Form1.Memo3.Lines[0]:=filename+'.MISSING'; Form1.Memo3.Lines.SaveToFile(path+filename+'.MISSING'); end; //Update status on Form1 Form1.total.Caption:='Checked : '+IntToStr((missing+good+bad)); Form1.bad.Caption:='BAD : '+IntToStr(bad); Form1.good.Caption:='GOOD : '+IntToStr(good); Form1.missing.Caption:='MISSING : '+IntToStr(missing); end;
procedure CRCThread.doallCRC; var i:integer; begin good:=0; missing:=0; bad:=0; pathdelim := LastDelimiter('\\',Form1.filename); filename:=copy(Form1.filename,pathdelim+1,length(Form1.filename)); path:=copy(Form1.filename,0,pathdelim); Form1.RichEdit2.lines.loadfromfile(path+filename); for I:=0 to Form1.RichEdit2.lines.count-1 do begin if ((pos(';',Form1.RichEdit2.lines[i])=0) and (Form1.RichEdit2.Lines[i]<>'')) then begin str:=Form1.RichEdit2.Lines[i]; Synchronize(doCRC); end; end; Form1.Statusbar1.simpletext:='Done'; end;
procedure CRCThread.Execute; begin //Synchronize(doallCRC); doallCRC; Terminate; end;
procedure MinThread.Execute; begin LabCaption:= 'Start'; Synchronize(SetLabelPaaHovedForm); //Din Kode ind her sleep(1000); LabCaption:= 'Slut'; Synchronize(SetLabelPaaHovedForm); end;
procedure MinThread.SetLabelPaaHovedForm; begin Form1.Label1.Caption:= LabCaption; end;
var filename, path, crc1, crc2, str:string; good,bad,missing,pathdelim : integer;
procedure CRCThread.abad(); begin Form1.Richedit1.Lines.Add(str+' BAD'); Form1.Memo3.Lines[0]:=filename+'.BAD'; Form1.Memo3.Lines.SaveToFile(path+filename+'.BAD'); end;
procedure CRCThread.amissing(); begin Form1.Richedit1.Lines.Add(str+' MISSING'); Form1.Memo3.Lines[0]:=filename+'.MISSING'; Form1.Memo3.Lines.SaveToFile(path+filename+'.MISSING'); end;
procedure CRCThread.updateform(); begin //Update status on Form1 Form1.total.Caption:='Checked : '+IntToStr((missing+good+bad)); Form1.bad.Caption:='BAD : '+IntToStr(bad); Form1.good.Caption:='GOOD : '+IntToStr(good); Form1.missing.Caption:='MISSING : '+IntToStr(missing); Form1.total.Update; Form1.bad.Update; Form1.missing.Update; Form1.good.Update; Form1.RichEdit1.Update; Form1.RichEdit2.Update; Form1.Update; end;
procedure CRCThread.doCRC(); begin filename:=copy(str,0,pos(' ',str)-1); crc1:=Lowercase(copy(str,pos(' ',str)+1,length(str))); if fileexists(path+filename) then begin crc2:=Lowercase(CRC.GetCRC32(path+filename)); if crc1<>crc2 then begin inc(bad); Synchronize(abad); end else if fileexists(path+filename+'.BAD') then DeleteFile(path+filename+'.BAD'); if fileexists(path+filename+'.MISSING') then DeleteFile(path+filename+'.MISSING'); inc(good); end else begin inc(missing); Synchronize(amissing); end; Synchronize(updateform); end;
procedure CRCThread.getfilename; begin filename:=Form1.filename; Form1.RichEdit2.Lines.LoadFromFile(filename); end;
procedure CRCThread.done(); begin Form1.Statusbar1.simpletext:='Done'; end;
procedure CRCThread.Execute; var i:integer; begin good:=0; missing:=0; bad:=0; Synchronize(getfilename); pathdelim := LastDelimiter('\\',filename); path:=copy(filename,0,pathdelim); filename:=copy(filename,pathdelim+1,length(filename)); for I:=0 to Form1.RichEdit2.lines.count-1 do begin str:=Form1.RichEdit2.Lines[i]; if ((pos(';',str)=0) and (str<>'')) then doCRC; end; Synchronize(done); Terminate; end;
end.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.