i use delphi 2007, zeos 6.6.3, mysql-5.1.24-rc, windows xp sp2 (libmysql.dll copy from mysql\mysql server 5.1\bin to project.exe folder)
Sorry for my bad english....
test dll code:
Code: Select all
library test_mysql;
uses
ShareMem,
SysUtils,
Classes,
Variants,
ZConnection,
ZDataset;
var
oldapp:thandle;
ZConnection: TZConnection;
ExecQuery:TZQuery;
function ConnectToDB:boolean;stdcall;
begin
result:=false;
ZConnection:=tZConnection.Create(application);
ZConnection.User:='root';
ZConnection.Password:='';
ZConnection.Port:=3306;
ZConnection.Protocol:='mysql';
ZConnection.Database:='mybase';
ZConnection.Properties.Add('codepage=cp1251');
ZConnection.HostName:='localhost';
try
try
ZConnection.Connect;
finally
ExecQuery:=TZQuery.Create(application);
ExecQuery.Connection:=ZConnection;
result:=true;
end;
except
ZConnection.free;
result:=false;
exit;
end;
end;
procedure LoadDLL(app:THandle);stdcall;
begin
oldapp:=application.Handle;
application.Handle:=app;
end;
procedure UnloadDLL;stdcall;
begin
application.Handle:=oldapp;
end;
function test:string;stdcall;
var r:string;
begin
if ZConnection.Connected=false then exit;
ExecQuery.SQL.Clear;
ExecQuery.SQL.Add('SELECT name FROM mybase.test');
ExecQuery.Open;
if VarIsNull(ExecQuery.FieldValues['name']) then r:='' else
r:=ExecQuery.FieldValues['name'];
result:=r;
ExecQuery.Close;
end;
exports ConnectToDB,UnloadDLL,LoadDLL,test;
end.
Code: Select all
unit Unit1;
interface
..........................
function ConnectToDB:boolean; stdcall; external 'test_mysql.dll';
procedure LoadDLL(app:thandle); stdcall; external 'test_mysql.dll';
procedure UnloadDLL; stdcall; external 'test_mysqld.dll';
function test:string; stdcall; external 'test_mysql.dll';
var
Form1: TForm1;
implementation
............................
procedure TForm1.FormCreate(Sender: TObject);
begin
LoadDll(application.handle);
ConnectToDB;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnloadDLL;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMesasge(test);
end;
end.