Hi Folks.
Made a small program using 2 listboxes and a command button to change the order of 10 delimited string values (separated by semicolons). Wanted the last word of each line in the text file to be first.
If I change the value of i in
T := RowArray[i].Split(';'); for a specific line it works for that line
Almost like the looping is not working.
I applied the steps:
1. Load text file in listbox1
2. Make a RowArray for each listbox row.
3 Split each listbox1 row
4. Make a new order of the strings.
5. Loop through the listbox1 by count and add to listbox2.
Here is my code:
unit delimited;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
bn_doIt: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
procedure bn_doItClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.bn_doItClick(Sender: TObject);
var
T, RowArray: array of string;
i : Integer;
begin
ListBox1.Items.LoadFromFile('Test.txt');
i := 0;
T:= Nil;
RowArray := Nil;
RowArray:= ListBox1.Items.ToStringArray;
begin
for i := 0 to ListBox1.Items.Count - 1 do
T := RowArray[i].Split(';');
ListBox2.Items.Add(T[10] + ';' + T[0] + ';' + T[1] + ';' + T[2] + ';' + T[3]
+ ';' + T[4] + ';' + T[5] + ';' + T[6] + ';' + T[7] + ';' + T[8] + ';' + T[9]);
end;
end;
end.