Text Spinner is a wizard application which allows the user to select a input file and declare an output file and have the application perform some task (Spin) on the input file and save it as the output file.
Using the arrow buttons in the footer of the application, you can move through the pages of the wizard
First, select the “Import File” to be processed.
Next, select the “Output File” to write the results to.
Then, move to the progress page to “Spin!”
Click the “Spin” button when your ready……
The application uses a thread to do the spinning, leaving you the capability to interact with the program (e.g. click the cancel button to stop and reset)
TSpinThread = class(TThread)
procedure SpinLine(const ALine: String; var ANewLine: String);
procedure Execute; override;
constructor Create(const AImportFile, AOutPutFile: String; AProgressBar: TProgressBar; OnThreadTerminate: TNotifyEvent);
When the thread’s Execute method is called, it create’s a StringList and Loads the Import File into it. It then Sets the progress bar’s max property based on the number of lines in the file. Then it steps through each line in the StringList and calls the SpinLine method on the line of text in the Stringlist. After it spins the line, the Line is returned back in the var parameter “NewLine” where it is then assigned back to the StringList to be written out as the Output file.
ImportList := TStringList.Create;
FMax := ImportList.Count;
for I := 1 to ImportList.Count – 1 do
if Terminated then
Sleep(1); //you can remove this line if you like
The SpinLine method allows you to do anything you want to the line (parse it, modify it, etc). In the example below, I am just iterating through each character in the line
procedure TSpinThread.SpinLine(const ALine: String; var ANewLine: String);
var I: Integer;
for I := 1 to Length(ALine) do
//do something to each character of ALine here
DOWNLOAD IT AND GIVE IT A SPIN! <SMILE>
Download Source and Executable
Another example of use would be to extract all words from a domain name. Read in a file of domain names, and write out a file of domain names and all the words found in the domain names. If you compare the two examples, you will see that the only difference is that I removed one page of settings from the application, and change the source code in the “Spin Line” procedure.