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!

Newbie in Delphi 2010,How to connect a VCL form with MySQL???

Status
Not open for further replies.

Christos75

Technical User
Apr 6, 2010
5
0
0
GR
First of all, congratulations to all of you for your help you provide in this forum!
I'm newbie in Delphi 2010 and I'm trying to connect a VCL form (login form with fields username & password) and mysql database. Please help me how to do that because I didn't find any forum-except this-to help me!
Thanx in advance for any help or answers...
 
Here a few options for database connections:

1.) Buy some libraries from the internet.
2.) Download the MySQL ODBC connector driver and install it. Set up an ODBC client (either manually or via code by accessing the registry) and use one of the two:
A.) BDE
B.) dbGo
3.) Use dbExpress (if you can get it to work).

Steve.
 
Thanx Steve for your answer!

1)Do I need to buy some libraries???If i don't???

2)In this step i need two programs... Download ODBC connector and ODBC client???After that, I have to use BDE or bdGo???

3)How to use dbExpress to install a connection between a VCL login form and Mysql database???
 
Are you writing this program for internal use (personal, interoffice, etc...)? Or are you selling this program for which you will have to create an installer? I can help you some with the first question. I have had zero experience creating installers.

One nice thing about purchased libraries is the fact you can buy libraries that do not require any DLL's, therefore no additional driver distribution/setup.

By the way, my first response was NOT a step-by-step description of what you have to do. INSTEAD, the three items in my first reply were OPTIONS, as in do one or the other. First, choose either 1.) or 2.) or 3.) as your plan of attack, then worry about the details of implementing either 1.) or 2.) or 3.)

All three options will involve throwing non-visual VCL onto your form, specifying server hostnames (or localhost if the server is on your development machine), etc...

If you are anxious to see data from your server appear in a TDBGrid, you can go ahead and download and install the MySQL ODBC connector and set up an ODBC client. You can find connectors at the following:
The above link has a link showing you step-by-step instructions ("Connector/ODBC Documentation") on how to set up an ODBC client in Winderz XP (same basic thing for Vista). The instructions ALSO include pretty screen shots.

At work I use drivers from At home I use the ODBC connector with dbGo.

Steve.
 
Thank you Steve for your replies!
First of all, I 'd like to write a program for personal use! I'd like to write a software for education! The program has the ability to train you in Mathematics.
The first thing is to create a logging form (VCL) which connect to a database(Mysql) and check if the username and password is correct. After that you could log in and will begin the test!
So,this is not a softaware which needs installer! I need it for me and my students!
The concept is to insert useraname & password and with a button "login" checks if these values are correct or not!
If they'll be correct you logged in,otherwise you'll have a negative message! That's all...after you logged in the test will begin!!!!
I have installed in my operating system (Windows 7) Delphi 2010!
How do I achieve that??
Thanks in advance for your time!
 
You may have already done these things, but just in case, let's start at the beginning:

1.) Download and install a MySQL server either on your PC or on a PC on your network (if you have one). From what you described, it would probably be easiest to install the server on the PC that will be running your program.
2.) Set up a few user accounts in your new database with which to experiment.
3.) Download and install the ODBC driver and set up an ODBC client. If you install the server on your development machine, you can use "localhost" for the hostname, which is what I recommend.

This should get you a good head start. I need to go home, now. If you have any questions regarding MySQL, there is a good, active MySQL forum here at
Once you have the server up and running we can continue with your program.

Steve.
 
Thanx again Steve and thanx for your time!

1) I'll download the Mysql Server and i will install it to my pc!

2)I'm going to set up a user account,for what reasons to create another one???Only to give a try(??)
Do i need to download Mysql Query browser??The GUI tool of mysql???

3)You advice me to download ODBC driver to set up ODBC client...what's the difference between these two..??

After these 3 steps what's the next???
 
I went through this several years ago. I could not find a bug-free driver but settled on "MySQL ODBC 3.51 Driver" (free download from MySQL site if I remember correctly) as the best for my purposes. I am sure drivers will have improved, but recommend you thoroughly test any solution. All will be OK with 32 bit integers, but check strings, nulls, floating points, blobs and anything vaguely exotic.

I used a TADOConnection with the following code. It dynamically creates the DSN.

Code:
procedure TMainMySQLData.ConnectionStringAction(AServer, ADatabase, AUser, APassword: string);
{Create, checks or modifies an ODBC DSN, and then provides that DSN name to
the Delphi connection.}
const
  c_DSN = 'MySQL_XXXXXXXX';
var
  LParams : string;
  LRequest : word;
begin
  {Build DSN friendly connection string}
  LParams :=
    'DSN=' + c_DSN + #0 +
    'Server=' + Trim(AServer) + #0 +
    'DataBase=' + Trim(ADataBase) + #0 +
    'User=' + Trim(AUser) + #0 +
    'Password=' + Trim(APassword) + #0 +
    'Description='#0 +
    'Option=' + IntToStr(1 + 2048) + #0;
                   {1 =  Don't optimize column width
                    2 = Return matching rows
                    4 = Trace driver calls to myodbc.log
                    8 = Allow big results
                    16 = Don't prompt upon connect
                    32 = Enable dynamic cursor
                    64 = Ignore # in table name
                    128 = Use manager cursors
                    256 = Dont use set locale
                    512 = Pad CHAR columns to full column length
                    1024 = Return table names for SQLDescribeCol
                    2048 = Use compressed protocol}

  {Validate DSN}
  if not IsDSNExists(c_DSN) then
    LRequest:=ODBC_ADD_DSN else
    LRequest:=ODBC_CONFIG_DSN;

  if not SQLConfigDataSource(0, LRequest, 'MySQL ODBC 3.51 Driver', PChar(LParams)) then
    Raise Exception.Create('Cannot configure ODBC DSN for XXXXXXX database' +
     #13'This program requires the driver: "MySQL ODBC 3.51 Driver"');

  {Set Delphi connection object parameters}
  MainConn.LoginPrompt := False;  // MainConn is a TADOConnection
  MainConn.ConnectionString := 'Provider=MSDASQL.1;Persist Security Info=False;Data Source='+c_DSN;
end;
 
We could insert the code above in a VCL form???
How create our database???In Delphi 2010(dbExpress) or with mysql Query Browser???
 
>We could insert the code above in a VCL form???
Yes. Place a TADOConnection on the form.

The database can be created in many ways. For develop of teh database itself I usually use external tools like MySQL Query Browser rather than Delphi.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top