FindAllFiles lazarus / 62-General ---------------------------------------------------------------------- tjpren · 2011-12-02 10:28 Hi Guys, I've written a basic search program. I'm using the FindAllFiles Procedure, and it is working very well. I'd like some indication that a search is active, and so I've created a button that changes colour during a search. However it is not working. If I don't execute the FindAllFiles, the button changes.  If I do execute a search, the button doesn't change.  Something about the search stops the button colour change. Does anyone know of an event in the FindAllFiles that I could yse instead? Thanks ---------------------------------------------------------------------- typo · 2011-12-02 10:49 This works fine: Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var   Path, Mask :string; begin   Path := 'c:\';   Mask := '*.txt';   Shape1.Brush.Color := clRed;   Memo1.Lines.Clear;   Application.ProcessMessages;   Memo1.Lines := FindAllFiles(Path, Mask, True);   Shape1.Brush.Color := clLime;   Application.ProcessMessages; end; ---------------------------------------------------------------------- tjpren · 2011-12-02 12:12 Hello, thanks for this. It doesn't seem too different to mine - I'm just calling a procedure and dumping the results into a list box.  I've found that if I add a messagebox after I make the colour change but before I make the search, the shape does change colour.  It's as if the colour change takes time, and gets interrupted by search. Code: [Select]Procedure TForm1.Search; var   sl: TStringList;   i: Integer; begin   sl := FindAllFiles(Edit1.Text, Edit2.Text, True);   try     //Memo1.Append('There are ' + IntToStr(sl.Count) + ' pascal files in directory');     for i:=0 to sl.Count-1 do         //Memo1.Append('File'+IntToStr(i)+': ' + sl.Strings[i]);           ListBox1.Items.Add('File'+IntToStr(i)+': ' + sl.Strings[i]);     finally     sl.Free;     Shape1.Brush.Color :=clGreen;   end; end;  procedure TForm1.Button1Click(Sender: TObject); begin   Shape1.Brush.Color :=clRed;   Search; end; ---------------------------------------------------------------------- eny · 2011-12-02 12:17 Quote from: tjpren on December 02, 2011, 01:12:12 pmIt doesn't seem too different to mineAny idea why typo put ' Application.ProcessMessages;' in there, which is a huge difference compared to your code? ---------------------------------------------------------------------- typo · 2011-12-02 12:35 Yes, this is the problem. BTW, you use FindAllFiles correctly, very good. My code has probably a memory leak. ---------------------------------------------------------------------- tjpren · 2011-12-02 23:09 Thanks for the help, and pointing out the Application.ProcessMessages. I've added the instructions to my code and the color change on the button now works OK. If I understand it correctly, it allows time consuming threads to be completed concurrently, giving low priority tasks such as the button change the opportunity to complete. I'll have to read more in the wiki, on how and when to use it. Regards