You can put the file scan files into a stream, and upon completion, send a Windows message to the main form, which will then update the list window (code not tested, take it as a pseudo-code):
const WM_FILESEARCH_FINISHED = WM_USER + 1; TFileSearchThread = class (TThread) private FPath : String; FFileNames : TStringList; protected procedure Execute; override; public constructor Create (const Path : String); destructor Destroy; override; property FileNames : TStrings read FFileNames; end; constructor TFileSearchThread.Create (const Path : String); begin inherited Create (True); FPath := Path; FFileNames := TStringList.Create; end; destructor TFileSearchThread.Destroy; begin FreeAndNil (FFileNames); inherited; end; procedure TFileSearchThread.Execute; begin // do your file search here, adding each file to FFileNames PostMessage (MainForm.Handle, WM_FILESEARCH_FINISHED, 0, 0); end;
You can use it as follows:
Thead := TFileSearchThread.Create (Path); Thread.Start;
and in the main form there will be a message handler as follows:
type TMainForm = class(TForm) ListBox1: TListBox; private procedure WMFileSearchFinished (var Msg : TMessage); message WM_FILESEARCH_FINISHED; public { Public declarations } end; implementation procedure TMainForm.WMFileSearchFinished (var Msg : TMessage); begin ListBox1.Items.AddStrings (Thread.FileNames); end;
source share