>I was advised on DUG way back to not to mix tables with queries. I dont recall quite
>what the reasons were, but I
>elected to use tables, and to create them using database desktop.
>I now find a need to display a table sorted on a secondary index, apparently an easy
>feature of tquery. Can anyone
>see a wise and simple resolution of this? Can I stick with tables, and is wise to do
>so?
There are 2 models called Tables one in the database and one in the application...
Your application is broken into at least 2 layers.
Database Layer:
Although not the only paradigm nearly all database organise their dat in tables with
fixed numbers of columns of
prespecified types. This is what you are doing in Database Desktop.
Application Layer (and usually supported in the database layer)
Viewing information can be performed by esentially two methods.
Tables:
this is an unfiltered grabs of the table in the same form it is stored, all columns
and all rows (filtering may be
performed by the application after retrieval but the filtering is still done AFTER
getting all the data).
Queries:
Selection of specific columns from several tables according to a search clause to
'synthesise' a new table
that answers more specifically the task at hand. Generally filtering of rows and this
collection is performed
by a database server but for some database types (Paradox) the filtering is the same
as for tables and
performed after getting all the data.
Delphi provides these Application paradigms as TTable and TQuery.
Imagine a table of employees with an employee ID, Name and 10 other fields...
---------------Example TTable usage...------------------------
Combobox1.Items.Clear;
with TTable.Create(nil) do try
DatabaseName := 'MyAlias';
TableName := 'MyTable';
{Note that I haven't used ttables for a while} IndexFieldNames := 'Title';
Open;
while not EOF do begin
Combobox1.Items.AddObject(FieldByName('Title').AsString,TObject(FieldByName('ID').AsInteger));
Next;
end;
finally
Free;
end;
---------------Example TTable usage...------------------------
Combobox1.Items.Clear;
with TTable.Create(nil) do try
DatabaseName := 'MyAlias';
SQL.Text := 'SELECT TITLE,ID FROM MyTable ORDER BY UPPER(TITLE)';
Open;
while not EOF do begin
Combobox1.Items.AddObject(Fields[0].AsString,TObject(Fields[1].AsInteger));
Next;
end;
finally
Free;
end;
I would definitely recommend moving to an SQL based implementation so that
even if you do not move to Interbase immediately your transition will be smoother.
--
Aaron Scott-Boddendijk
Jump Productions
(07) 838-3371 Voice
(07) 838-3372 Fax
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz