I've made a wee program in Pascal, that iterates through all the .txt files in a given directory. It then loads a text file into a sorted TStringList, saves it, and repeats for the next .txt file.
Trouble is, I need a wee indicator telling me that it's actually doing something. I added such a thing, but the UI doesn't update whilst the pretty hefty function is running.
In C#, you'd just have to:
Spawn a thread that runs the intensive function:
Task taskLoadTextFileIntoWorksheet = Task.Factory.StartNew(() => //Code here )
And just chuck in the UI changing stuff inside a delegate procedure-ish thing:
Invoke(new MethodInvoker(delegate {//CodeGoesHere}) )
Ya can see my working example in C# 'ere:
https://github.com/MajinCry/Fallout-4---Dialog-Renamer/blob/master/WindowsFormsApplication3/Form1.csLuckily, my Pascal program is waaaaay simpler.
https://github.com/MajinCry/Multiple-Text-File-Sorter/blob/master/programwindow.pashttps://github.com/MajinCry/Multiple-Text-File-Sorter/blob/master/mainprogramcode.pasProgramWindow contains all the UI guff, with MainProgramCode doing all the work. What I'd like to do, is chuck the
SortTextFilesInDir()
function into it's own thread, so the UI doesn't hang, and then chuck in
editToUpdate.Text := tstrlistTextFilesInDir[iCounter];
into a delegate, to update the UI.
But this isn't C#, and the Lazarus wiki is down. What do?
One of the techniques I've read, that doesn't rely on poorly-optimized boilerplate, is to use an event messaging system (w/e that means). No idea about that stuff, 'tis way over my head, so I'd need some pretty dang fine hand holding with that.
I'd guess that it's something along the lines of creating a listener in ProgramWindow.pas, that has a call to
procedure OnUpdateCurrentTextFileDisplayed(strReceivedFilename)
, which would have the
editToUpdate.Text := tstrlistTextFilesInDir[iCounter];
line inside it.
But again, no idea on how to actually do that.