Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Migrating from vb to delphi II

Posted on 1999-06-25
12
Medium Priority
?
185 Views
Last Modified: 2010-04-06
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
IT GIVES ME INVALID OR CORRUPT HEADER, BUT THIS DATABASE WORKS FINE WITH VB.

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)
tmp=rs(0)
in delphi?????


I'M GIVING A 50 POINTS SPEED BONUS

THANKS IN ADVANCE
0
Comment
Question by:ElvasLion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 15

Expert Comment

by:simonet
ID: 1384554
>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.

3)
procedure LoadText(Table, Field : string);
var
 SQL : string
begin
 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
 Query1.Open;
 ...

YOurs,

Alex
0
 
LVL 15

Expert Comment

by:simonet
ID: 1384555
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.

Yours,

Alex
0
 
LVL 1

Author Comment

by:ElvasLion
ID: 1384556
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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:ElvasLion
ID: 1384557
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
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1384558
* 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) :

http://www.torry.ru/samples/samples/d2access.zip

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.
0
 
LVL 1

Author Comment

by:ElvasLion
ID: 1384559
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)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1384560
mmmmm....

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?

Zif.


0
 
LVL 1

Author Comment

by:ElvasLion
ID: 1384561
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
0
 
LVL 15

Expert Comment

by:simonet
ID: 1384562
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:

YOUR APPLICATION
           |
BORLAND DATABASE ENGINE (BDE)
           |
MICROSOFT ACCESS DATABASE

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.

Yours,

Alex
0
 
LVL 1

Author Comment

by:ElvasLion
ID: 1384563
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.
thans
0
 
LVL 15

Accepted Solution

by:
simonet earned 400 total points
ID: 1384564
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.

Yours,

Alex
0
 
LVL 1

Author Comment

by:ElvasLion
ID: 1384565
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.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question