Hi all.
I would first like to salute the Lazarus development team and their amazing work: I have been following Lazarus since a version 0.9 but with the 3.4 that I have just discovered it is the first time that I find it really usable.
I come from C++ Builder because over time licenses become horribly expensive and with less features with the basic versions; So I came back to Lazarus even though I have no real experience in Pascal.
So to test I wanted to create a small application to connect to a Mysql database and I adapted some code for beginners that I found on developpez.com, where the Mysql functions to be used in the program are grouped in a DataModule.
Here is the code:
unit DataAccess;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, mysql80conn, SQLDB, Dialogs,db;
type
{ TDataModule1 }
TDataModule1 = class(TDataModule)
SQLConnection1: TMySQL80Connection;
SQLTransaction: TSQLTransaction;
private
public
function Login: Boolean;
procedure Logoff;
end;
var
DataModule1: TDataModule1;
implementation
{$R *.lfm}
{ TDataModule1 }
function TDataModule1.Login: Boolean;
begin
Result := true;
SQLConnection1.Hostname := '*';
SQLConnection1.DatabaseName := '*';
SQLConnection1.UserName := '*';
SQLConnection1.Password := '*';
try
SQLConnection1.Connected := true;
SQLTransaction.Active := true;
except
on e : ESQLDatabaseError do
begin
MessageDlg('Erreur de connexion à la base :'#10#10#13 + IntToStr(e.ErrorCode) + ' : ' + e.Message + #10#10#13'Application terminée.',mtError,[mbOK],0);
Result := false;;
end;
on e : EDatabaseError do
begin
MessageDlg('Erreur de connexion à la base :'#10#10#13'Application terminée.',mtError,[mbOK],0);
Result := false;;
end;
end;
if Result = true then
MessageDlg('Base disponible!',mtError,[mbOK],0);
end;
procedure TDataModule1.Logoff;
begin
if SQLTransaction.Active then
SQLTransaction.Active := false;
if SQLConnection1.Connected then
SQLConnection1.Connected := false;
end;
end.
The problem is that this code does nothing: no dialog box appears either in case of error or in case of successful connection (The form is created first in the Project options)
I then wanted to test the connection with the properties of SQLConnexion (Connected) and SQLTransaction (Active) but then I get the message "Unable to load libmysql.dll".
After a lot of research I was able to get libmysql.dll (64 bits for Windows 11, Version 8.037) and I placed it in several places, with the .exe of my application, the Lazarus.exe, various other places in the path and nothing helps, I always get the same message.
In C++ Builder you can specify the location of libmysql.dll in the properties of a component but in Lazarus I couldn't find anything like that?
Could someone tell me if
1° Is my code correct?
2° If so, why does it seem not to be executed?
3° Where to place the libmysqll.dll so that it may be recognized by Lazarus
4° If the two problems are linked?
Thank you very much in advance!