Solved

Delphi TSQL Connection runtime creating

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

809 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