Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetTableNames: I want to display t

Status
Not open for further replies.

goodmanrAy

Programmer
Feb 6, 2002
53
GB
GetTableNames:
I want to display the table names in a combo box in chronological order not alphabetical order like they are at the moment
e.g. the files name are January02, Febrauary02 etc

var mylist : TStringList;
begin
MyList := TStringList.Create;
Try Session.GetTableNames('C:\My Documents\'.'*.db',false,false,MyList);
Combo1.items := MyList;
finally
MyList.Free;
end;



Any ideas?
 
Use the One True Date Format -- ANSI date. Dates are formatted like yyyymmdd; i.e. May 14th 2002 is 20020514. This has the singular advantage that you can sort ANSI dates alphabetically or numerically, and they'll wind up in date order.

ANSI date doesn't support dates without a day field, like yours; but you could just set the day to 01, say.

Either rename your tables so that they follow ANSI date (this would be simple and robust), or internally tag your list elements with an ANSI date, sort them on it, and then delete the tags again:
Code:
  for i := 0 to MyList.Count - 1 do
    MyList[i] := DateStrToAnsi(MyList[i]) + ';' + MyList[i];

  MyList.Sort;

  for i := 0 to MyList.Count - 1 do
    MyList[i] := Copy(MyList[i], Pos(';', MyList[i]) + 1, 999);
Writing DateStrToAnsi() is left as an exercise for the reader. :) -- Doug Burbidge mailto:doug@ultrazone.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top