• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

Migrating from vb to delphi II

I need to know how to do some thing in delphi in comparison to what i do in vb.

1. I still can´t use msaccess tables in delphi i do thge fallowing with dbtable1 at design time:
databasename --> c:\test
tablename    --> DB1.MDB

2. in vb i use the combobox proprety text to store the name, the index to store the position and the itemdata to store anything that i think useful(normaly i store there the id of the field). I can i do this in delphi???

3. I have a procedure in vb to do this:
call load_text(table as string, field as string)
sql="select " & field & "from " & table
sql=sql & " where id=" & text1.text
set rs=db.openrecordset(rs)
in delphi?????


  • 6
  • 4
  • 2
1 Solution
>tablename    --> DB1.MDB

Nope. TableName must point to the actual table inside DB1.MDB. A MDB file is not a table, but several tables, macros, forms, etc, grouped together in one big file. There must be one table inside the MDB to which you want to point, isn't there?

2) YEs, must in Delphi there are even more useful properties, including the BOOKMARK option, that can save the binary position of the pointer inside the table. So it saves the position of the current record so you can quickly return to it. There are also indexes.

procedure LoadText(Table, Field : string);
 SQL : string
 SQL := Format('SELECT %s FROM %s WHERE ID=', [Field, Table, edit1.text]);
 Query1.SQL.Text := SQL; // I've already told you about the TQuery component


Another comment:

>databasename --> c:\test

Try this instead:

Databasename <-- C:\test\DB1.MDB

Or create an alias to this database (DB1.MDB) as seen in your first question.


ElvasLionAuthor Commented:
once again your answer is up to your reputation, and i will give you the points plus the 50 for shure, but before tell me a couple of things if you don´t mind:
1. I can´t understand the alias and the propertys of dbtables and dbdatabase. It keeps giving me that error i told you about.

2. Please tell me how to work with those indexes you told me about.

thanks again

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

ElvasLionAuthor Commented:
i coul´d bet that i had already posted this comment, but...
as always your answer is up to your reputation, and i will give you the points for shure. But before i just need to know a few things, so..

1. Please explain me the alias and other propertys of the dbtable because i simple can´t understand them.

2. Tell me how to work with those comboboxes indexes that you told me about

thanks again
* Aliases are created in the BDE administrator (or created through source code)
You can find the BDE Adminstrator in the Control Panel

Basically with aliases you can assign a name to a directory in which the database resides. Then, In your source-code you don't have to hard-code the PATH to the database. You put the alias in the source code. The BDE links the alias with the real PATH.

* You can make connection to a MSAccess database :
 1. with the help of an ODBC driver
 2. Since D3, also through a native Access driver

* When you use an alias, you put enter the name of the alias in the Databasename property. You enter the TABLE name to which you want to connect in the TableName property.

* You can also use a TDatabase component which you use as frontend connection to your MSAccess database. The TTable components then refer to this database component (i.e. DatabaseName property = TDatabase name).
This TDatabase component allows you to enter password strings etc, once.

This file gives you more information on how to connect to Access (I think only the ODBC way, I'm not sure) :


I advise you to read the Delphi Books or parts of them to get a notion of the indexes, because it's kinda hard to explain everything Delphi can do. Tell us the behavior you want to get with the comboboxes

Regards, Zif.
ElvasLionAuthor Commented:
thank you zifnab.
the behaviour i want is to store the autonumber of the field, getting it from the access table and then associating with the combobox item like this:

item     --> apple
index    --> 0
itemdata --> 3(the position in the access table)

item     --> peach
index    --> 1
itemdata --> 2(the position in the access table)

I'm not familiar with vb, so I don't know how the components work in vb.

Perhaps if you aswered these questions, I can get a better view on your problem :
why do you need this behavior? What is your goal?


ElvasLionAuthor Commented:
in the combobox we woul´d only see apple and peach but if we selected apple we woul´d get access to combo.index-->0
and combo.itemdata --> 3
ps. the itemdata coul´d contain integers or any other data type
Hello again, Elvas. Sorry for taking too long to get back to you, but I had to attend a couple meetings today. You know what these meetings are like. The last question is always: "When are you meeting again to solve the problems we were supposed to have solved in this meeting?"

Now, back to the database stuff:

An Alias is pretty much what the name says: it's a "nickname" you give to a set of definition you make within BDE.

When you write a Delphi program accessing an Access database, these are the layers the data is passing through:


Even although there's a native drive that connects BDE to Access, you have to configure several properties, which are specific to each application. For example: in APPLICATION-1 you access an Access database called STORE1.MDB, through a user called John. In APPLICATION-2 you're accessing another Access database called NORTHWIND.MDB, through another user. So, in order for you not to configure every piece of information everytime you want to use the first or the second scenario, you configure them only once, in BDE. This set of configuration is what we call an ALIAS.

If you go to BDE Administrator and study a few of the aliases, you see that they define some rules as to what the database is and how it should be accessed. When you need to use this set of rules regarding databases in your apps, it's often more convenient to create the rules (the configs) under an alias and refer to the alias in your application. An Alias points only to one database, but you can have the same database pointed by several aliases and use as many aliases as you want in your application (although in the most complex case I've seen 3 were enough. In most applications 1 alias will suffice).

Another great benefit of aliases is that when you move the configuration of the tables (like moving them to another database or another folder), you do not have to recompile the EXE. Just change the info on the Alias (using BDE Admin) on the alias that the EXE uses.

As you're coming from VB, I believe you've already used ODBC connections. You can think of an alias as an ODBC connection, although a BDE alias is something native to Delphi and BCB, and is **a lot** faster than ODBC.

So, and alias is a pointer to a database, which must be used under certain rules defined in the alias properties under BDE Admin. In your Delphi app, whenever a Database property is required (like in TTable, TQuery, TBatchmove, etc), you can simply assign the name of the alias to the database property.

A database is a collection of tables. Therefore, just setting the database property for most data access components is not enough. You also need to specify a TableName property. If you open your DB1.MDB database in Access, you'll see that there can be several tables in that single file.

Another important component is the TDatasource control. TDatasource is the component that provides data to VISUAL controls. Thus, if you're using a TDBEdit, you will link this TDBEdit control to the TDatasource, and the TDatasource will be connected to wherever the data is coming from (which can be a TTable, a TQuery, etc).

Better than writing code here from the top of my head and being subject to typos, I'll point you to a Delphi example of accessing databases. In the Delphi4\Demos\DB, there are a number of examples that cover database access and the usage of data-aware controls. Please take a look at them.

Delphi (just like VB, I believe), has a separate set of Edit boxes, labels, combo-boxes, grids, etc, for displaying data from datasources. You can find these components in the Data aware component palette. Remember that you need to use a TDatasource to interface these components to the TTable or TQuery.

Let me know what else is missing.


ElvasLionAuthor Commented:
Thanks evrybody, but i feel oblieged to give the 100 points to simonet, but i will post a 50 points question for zifnab.
without trying to abuseof you i still woul´d like to know the index stuff.
Thank you very much, ElvasLion.

A quick note about indexes:

Indexes are definitions that tell the database in what sequence the data must be accessed. I am not sure about how Access work with indexes, but Paradox, dBase, Oracle, MS SQL, Interbase, DB2, Sybase and most other well know database servers work with them and they are visible to Delphi's data access components, so you can specify the index either in design time or runtime.

The can be one primary index and several secondary indexes. Except for the primary index, indexes do not change the way (or the position where) data is stored in the database. However, when working with SQL statements, well defined indexes can speed up queries a lot.


ElvasLionAuthor Commented:
Thank you a lot alex. I´m looking forward your help whenever i have problems.

i´ll post a 50 points question only to you ziffnab if you e-mail me regarding that.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now