Page 1 of 1

DLL incapsulation of TMyConnection Problem

Posted: Wed 14 Nov 2007 07:20
by saidus
Hello !!!
I work on an application that call a function from a DLL
the Code :

Code: Select all

Procedure CalcCDE(c : TMyConnection;nt : string ); stdcall ;
{  c : will be the Application Connection}
var
        tCn : TMyConnection ;  
begin
            try
            tCn := TMyConnection.Create(nil);
            tCn.Username := c.Username;
            tCn.Password := c.Password;
            tCn.Server   := c.Server;
            tCn.Port     := c.Port;
            tCn.Database := c.Database;
           // tCn.Connect;
        except on E:Exception do
           ShowMessage('0 : ' + E.Message);
        end;
       { Dm.c_Cde : is TMyCommand in Datamodule    in DLL Projects}
        try
          Dm.c_Cde.Connection := tCn;
          tCn.Connect;
        except on E:Exception do
           begin
                ShowMessage('1 : ' + E.Message);
                tCn.Close;
                tCn.Free;
           end;
        end;
       { ==============================}
       {   try to full parameters of  DataSets                } 
       { Dm.c_Cde : is TMyCommand in Datamodule    }
       {==============================}
        try
          Dm.c_Cde.ParamByName('a').AsString := nt;
          Dm.c_Cde.ParamByName('b').AsString := nt;
          Dm.c_Cde.ParamByName('c').AsString := nt;
          Dm.c_Cde.ParamByName('d').AsString := nt;
        except on E:Exception do
           begin
                ShowMessage('2 : ' + E.Message);
                tCn.Close;
                tCn.Free;
           end;
        end;
       { ======================== }
       {  Executing the Querys & ..               ...}
       { ========================}
         try
              Dm.c_Cde.Execute;
         except on E:Exception do
           begin
                ShowMessage('3 : ' + E.Message);
                tCn.Close;                
                tCn.Free;
           end;
         end;
       { =========================}
       {  Free Allocated ressources               ...}
       { ==========================}
         tCn.Close;
         tCn.Free;
end;
{ ==========================}
{  Exported Functions                                }
{===========================}
EXPORTS CalcCDE;
in my app when i cal it i use :

Code: Select all

procedure TDm.DCdeAfterPost(DataSet: TDataSet);
var
       t : String;
begin
       t :=CdebsCdCde.Value;
       CalcCDE(MyCnt,t);
end; 
it gives me Error Reading Adress in all the blocs that i've protected by try..except
I Use Delphi 5 + MyDac 4.40.25
Please help me !
thanks u :oops:

Posted: Wed 14 Nov 2007 10:24
by saidus
thanks to all !!
I've resolved the Problem
!!
I've deleted the datamodule and create the TMyCommands an TmyQuery s dynamically so i Assigned the Connection of all components to c
there is the code :

Code: Select all

Procedure CalcCDE(c : TMyConnection;nt : string ); stdcall ; 
{  c : will be the Application Connection} 
var 
        tCn : TMyCommand ;  
begin 
        try 
            tCn := TMyCommand.Create(nil); 
 	tCn.Connection := c
	tCn.SQL.add(s);
            tCn.ParamByName('a').AsString:=nt
            tCn.Execute;      
        except on E:Exception do 
           begin
		ShowMessage('0 : ' + E.Message); 
		tCn.Free;
	   end;	
        end;  
         tCn.Free; 
end; 
{ ==========================} 
{  Exported Functions                                } 
{===========================} 
EXPORTS CalcCDE;