Board index » delphi » Help Tables to Query

Help Tables to Query

I am modifing an older program that is using tables.
I would like to give the user the opertunity to sort on fields.
I did not see anything on sorting tables.
I did see that sorting could be done with Querys.
I was trying to use the information contained on page 425 of the Delphi
Developers Guide (Sams).
I am opening a file using the opendialog component.
************************************
How do I get the filename in the Select * FROM area?
************************************
This is some of my code
  if (Path <> '') then
    OpenDialog1.InitialDir := Path;
  if OpenDialog1.Execute then
    begin
       With Query1 Do
        begin
          Close;
          SQL.Clear;
          DatabaseName := ExtractFilePath(OpenDialog1.FileName);
          pathsav      := ExtractFilePath(OpenDialog1.FileName);
          fname        := ExtractFileName(OpenDialog1.FileName);
          SQL.ADD('SELECT * FROM fname ORDER BY Machine_ID');
          Open;
          DirPathLabel.Caption  := pathsav;
          IFile.SetPath(pathsav);
          FilenameLabel.Caption := fname;
          Screen.Cursor   := CrHourGlass;
          ProcessFile(NIL);
          Screen.Cursor   := CrDefault;
          numrecs := Query1.RecordCount;

          Label34.Caption := IntToStr(numrecs);

          SysUtils.FindFirst(OpenDialog1.Filename,faAnyFile,SearchRec);
          FileCreationLabel.Caption :=
DateToStr(FileDateToDateTime(SearchRec.Time));
          SysUtils.FindClose(SearchRec);

        end;
    end
  else
    close;

 

Re:Help Tables to Query


Quote
Lawrence Leary wrote:
>  I am modifing an older program that is using tables.
> I would like to give the user the opertunity to sort on fields.
> I did not see anything on sorting tables.
> I did see that sorting could be done with Querys.
> I was trying to use the information contained on page 425 of the
> Delphi Developers Guide (Sams).
> I am opening a file using the opendialog component.
> ************************************
> How do I get the filename in the Select * FROM area?
> ************************************
> This is some of my code
>   if (Path <> '') then
>     OpenDialog1.InitialDir := Path;
>   if OpenDialog1.Execute then
>     begin
>        With Query1 Do
>         begin
>           Close;
>           SQL.Clear;
>           DatabaseName := ExtractFilePath(OpenDialog1.FileName);
>           pathsav      := ExtractFilePath(OpenDialog1.FileName);
>           fname        := ExtractFileName(OpenDialog1.FileName);
>           SQL.ADD('SELECT * FROM fname ORDER BY Machine_ID');
>           Open;
>           DirPathLabel.Caption  := pathsav;
>           IFile.SetPath(pathsav);
>           FilenameLabel.Caption := fname;
>           Screen.Cursor   := CrHourGlass;
>           ProcessFile(NIL);
>           Screen.Cursor   := CrDefault;
>           numrecs := Query1.RecordCount;

>           Label34.Caption := IntToStr(numrecs);

> SysUtils.FindFirst(OpenDialog1.Filename,faAnyFile,SearchRec);
>           FileCreationLabel.Caption :=
> DateToStr(FileDateToDateTime(SearchRec.Time));
>           SysUtils.FindClose(SearchRec);

>         end;
>     end
>   else
>     close;

> Hi Lawrence,

To sort a Table, by a field, you need to make a secondary indexthat uses
that field.  Each field that you want to sort on, has to have its
own secondary index (which also creates a separate index file on disk).

A Query is more powerful to sort multiple ways, and does not require
any secondary indexes.  But a Query has some other limitations
on data modifications and database updating (live data).

If you need more help, email me.

Good Luck,

Frank

Re:Help Tables to Query


Quote
> am modifing an older program that is using tables.
>I would like to give the user the opertunity to sort on fields.
>I did not see anything on sorting tables.
>I did see that sorting could be done with Querys.
>I was trying to use the information contained on page 425 of the Delphi
>Developers Guide (Sams).
>I am opening a file using the opendialog component.
>************************************
>How do I get the filename in the Select * FROM area?
>************************************
>          SQL.ADD('SELECT * FROM fname ORDER BY Machine_ID');

assuming fname is a string variable holding the table name

SQL.ADD('SELECT * FROM '+fname+' ORDER BY Machine_ID');

--
Brian Bushay (TeamB)
Bbus...@DataGuidance.com

Other Threads