I'm making a program that involves the copy and pasting of a piece of text into a TEditBox and submitting the text into 4 different columns in a TListBox. This program is actually for a game called FlashFlashRevolution (great free, online, ddr-like game if anyone wants to try it out). I thought you might need to know that for what I'm about to say next.

I know that the way to add columns to a TListBox is like:

ListBox1.Items.Add('Text'^I'Text'^I'Text'^I'Text') ;

At first I tried to do something like (at least I'm pretty sure this is how I set it up...):

ListBox1.Items.Add('EditBox1.Text'^I'EditBox2.Text'^I'EditBox3.Text'^I'EditBox4.Text') ;

I was kind of hoping that this would work so that it would at least be possible for the user to input there own stuff into each column, but this didn't work.
So instead what I did was I made it so

ListBox1.Items.Add('Rank'^I'Difficulty'^I'Song'^I'Score') ;

appeared on FormCreate to differentiate what would be in each column. Then I set up a TEditBox where the user can paste copied scores from the clipboard into and have them be added to the TListBox (like bellow).

procedure TForm1.AddClick(Sender: TObject);
    ListBox1.Items.Add(Edit1.Text) ;

The input string of the user looks something like (Rank, Difficulty, Song, Score):
1 2 Excite Bike 49,600*

The problem with this is that I don't think each string is being sorted into each column. My question to the community is: is it possible to sort something in the setup [above] into its corresponding columns from just a single EditBox or is it possible to setup something similar to ListBox1.Items.Add('EditBox1.Text'^I'EditBox2.Text'^I'EditBox3.Text'^I'EditBox4.Text')? The reason for wanting this is that I kind of want to be able to sort the stuff in the TListBox by lowest - highest and highest - lowest numeric values (for rank, difficulty and score), alphabetical (for song name), and if the score has a * or not (this indicates if the song is full combo which is when the player hits all the arrows).

Perhaps, I haven't fully understood your question but it seems to me that you are going about things in a somewhat complicated way. Firstly, by far the neatest way to add entries to a list view goes something like this

  • Use the ListView.Items.Add method to add a new row
  • Assign the "Caption" property for that row
  • Use the SubItems.Add method to add the other column entries

Once you have done this there remains the sorting issue. TListView offers an OnCompare event that is supposed to help with the task of custom sorting. In practice it is badly bugged and the results are rarely satisfactory. A better approach is to do the following

  • Assign an OnColumnClick event handler
  • In that handler call the CustomSort method of the list view.
  • You need to provide a callback function to CustomSort to establish list order. There is adequate information in the Delphi help file on this subject
This article has been dead for over six months. Start a new discussion instead.