Solved

Delphi TSQL Connection runtime creating

Posted on 2014-07-31
1
1,039 Views
Last Modified: 2014-08-01
i'll trying to create tsqlconnection at runtime, but i get this error :
SQLConnectionProperty required for this operation.
what i am doing wrong?


procedure grid_select();
var
  fotabla_grid_conn_msh   : TSQLConnection;
  MSHQuery_fotabla_grid : TSQLQuery;

begin
create_connection( fotabla_grid_conn_msh, f_foablak );
MSHQuery_fotabla_grid:= TSQLQuery.Create(self);
MSHQuery_fotabla_grid.SQLConnection := fotabla_grid_conn_msh;
MSHQuery_fotabla_grid.Name := 'MSHQuery_fotabla_grid';
end;

procedure Tf_foablak.create_connection ( P_CONNECTION_NAME : TSQLConnection; P_FORM : TForm );
begin
    P_CONNECTION_NAME:= TSQLConnection.Create(P_FORM);
            P_CONNECTION_NAME.ConnectionName := P_CONNECTION_NAME.ConnectionName;
            P_CONNECTION_NAME.DriverName := 'MySQL';
    P_CONNECTION_NAME.Params.Clear;
            P_CONNECTION_NAME.LoginPrompt := False;
            P_CONNECTION_NAME.Params.Add('DriverName=MySQL');
            P_CONNECTION_NAME.Params.Add('HostName='+f_foablak.ComboBox1.Text);
            P_CONNECTION_NAME.Params.Add('Database=microshop');
            P_CONNECTION_NAME.Params.Add('User_Name=rt');
            P_CONNECTION_NAME.Params.Add('Password=MiC85HarV01');
            P_CONNECTION_NAME.Params.Add('BlobSize=-1');
            P_CONNECTION_NAME.Params.Add('ErrorResourceFile=');
            P_CONNECTION_NAME.Params.Add('LocaleCode=0000');
            P_CONNECTION_NAME.Params.Add('Compressed=False');
            P_CONNECTION_NAME.Params.Add('Encrypted=False');
            P_CONNECTION_NAME.Params.Add('Use Procedure Bodies=False');
            P_CONNECTION_NAME.Params.Add('character_set_client = utf8');
            P_CONNECTION_NAME.Params.Add('character_set_connection = utf8');
            P_CONNECTION_NAME.Params.Add('character_set_results = Latin2');
            P_CONNECTION_NAME.Params.Add('CharSet=WIN1252');
            P_CONNECTION_NAME.Params.Add('ServerCharSet=UTF8');
            P_CONNECTION_NAME.Params.Add('UseUnicode=True');

            P_CONNECTION_NAME.GetDriverFunc := 'getSQLDriverMYSQL';
            P_CONNECTION_NAME.KeepConnection := True;
            P_CONNECTION_NAME.LibraryName := 'dbxmys.dll';
            P_CONNECTION_NAME.LoadParamsOnConnect := False;
            P_CONNECTION_NAME.VendorLib := 'libmysql.dll';

            P_CONNECTION_NAME.Connected := True;


end;
0
Comment
Question by:RT_
1 Comment
 
LVL 25

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 40234029
you should use var keyword - because your newly created object will get new instance:

...
procedure Tf_foablak.create_connection (var P_CONNECTION_NAME : TSQLConnection; P_FORM : TForm );

..

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now