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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi and FoxPro

Status
Not open for further replies.

wrov

Programmer
Nov 1, 2002
43
0
0
PY
Hello everybody:

In FoxPro you can write:

Procedure OpenFiles
Parameters TableName

USE &TableName

Return


And, in your main program write:

do OpenFiles with "CUSTOMER"


Is possible to do some like that in Delphi ?


Thanks in advance

Walter.
 
Walter,

Sort of, though Delphi's way of using tables is different than FoxPro's. In Delphi, you create a data module with ADO components pointing to the tables. Next, you create your client form, use the datamodule, place the visual components you need, and then connect them to the ADO components in your dataModule.

This design work saves you from writing code, for the database access is built into the connections between the components and there's no need to open the table in code.

However, if you want to do so, you can. Simply set properties of either your ADOTable and ADOConnection objects in the data module.

Hope this helps...

-- Lance
 
Thank you Lance

Well, I know all that but the idea is the following:

- To have a procedure than take as parameter the name of the table
- Open or select that table

For example, I want to have a DBGrid that show me the fields of the selected table (wichever it was).

Walter.
 
Drop a database component on a datamodule (found in the BDE tab) or the form you are showing and connect it to the database in question. Drop a SQL component on the datamodule. (I'll name it qryTableName) write SQL for qryTable like 'SELECT * FROM TABLE' or 'SELECT * FROM :TABLE' (I'll explain the difference in a minute)

If you choose the first one then you can use the following code:

With DataModule.qryTableName do
begin
SQL.Clear;
SQL.Add('SELECT * FROM ' + strTableName);
Active := True;
end;

The second method uses parameters and I have recently found that when running many queries against large databases this method can be much slower:

With DataModule.qryTableName do
begin
ParamByName('TABLE').AsString := strTableName;
Active := True;
end;

There are also some other configurations that have to be set to use this method. I would suggest the first method.

Then drop a DataSource component (Data Access tab - I'll name it dsTableName) set it's DataSet property to qryTableName. Set the DataSource property of the DBGrid to dsTableName. Then add the columns you need into the DBGrid and select the field from the query that you want to show in the grid.

It sounds complicated, but it's really easy. Mostly drop and drag, set some properties and you're good to go.

Hope that helps



Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top