Solved

Delphi TSQL Connection runtime creating

Posted on 2014-07-31
1
1,080 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 26

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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…

861 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

25 Experts available now in Live!

Get 1:1 Help Now