Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TADOConnection in a Delphi Package

Status
Not open for further replies.

tchant

Programmer
Jan 1, 2020
1
AU
Hi All,
New to this forum so I hope I'm in the right place, I have a bunch of Delphi Services running on a server , they basicly translate a incoming file into a standard format and then get inportrd into a Progress DB.It also exports a files in all sorts of formats including XML pipe seperated , csv etc. There are quite a few of these (Services) running and each service does a unique connection to the DB through ODBC.

The aim is to create a Delphi package and then share the package with the running services. I know I can share a DB connection using MyDAC to (MySQL) but for some reason I'm getting AV errors using ADO,I call the procedure CreateDataModule from the service (testApplication at this stage) and it creates the DM ( I load the *bpl at application startup) DM is created and the connection is established but when I connect the connection using "query1.Connection := datamod.lmsdata" I'm getting an AV error.

I would appriciate any advice or sample to guide me in the right direction.

Delphi XE7
Progress running on WIN Server2008 64bit

Unit for Data Module
========================
unit lmsdatamod;

interface

uses
System.SysUtils, System.Classes, Data.DB, Data.Win.ADODB, Registry, Windows,
IniFiles;

procedure CreateDataModule;

type
Tdatamod = class(TDataModule)
lmsdata: TADOConnection;

procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
datamod: Tdatamod;

implementation

{%CLASSGROUP 'System.Classes.TPersistent'}

//uses

{$R *.dfm}

function fReadStrFromIni(fSection,fComponent: string): String;
var IniFile : TIniFile;
begin
inifile := TIniFile.Create(ExtractFilePath(ParamStr(0))+ '\Servcontrol.ini');
try
with inifile do
result := ReadString(fSection,fComponent,'Error');
finally
inifile.Free;
end;
end;

function fCreateDSN: boolean;
var fReg : TRegistry;
begin
fReg:= TRegistry.Create;
try
if (not freg.KeyExists('Software\ODBC\ODBC.INI\LMSRPTDATA')) then
begin
if fReg.OpenKey('Software\ODBC\ODBC.INI\LMSRPTDATA', True) then
begin
fReg.WriteString('Driver', ExtractFilePath(ParamStr(0)) +'ODBC\pgoe1023.dll');
fReg.WriteString('Description', 'LMS Data');
fReg.WriteString('HostName', 'DGL-DEMO');
fReg.WriteString('PortNumber', '6521'); // check port number
fReg.WriteString('DatabaseName', 'lmsdev');
fReg.WriteString('LogonID', 'devel');
fReg.WriteString('Password', 'proper');
fReg.WriteString('StaticCursorLongColBuffLen', '4096');
fReg.WriteString('UseWideCharacterTypes', '0');
fReg.WriteString('EnableTimestampWithTimezone', '1');
fReg.WriteString('DefaultIsolationLevel', 'READ COMMITTED'); //was UNCOMMITTED
fReg.WriteString('ArraySize' , '50');
fReg.WriteString('DefaultLongDataBuffLen' , '2048');
fReg.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources', True);
fReg.WriteString('LMS ODBC CONNECTION', 'Progress OpenEdge 11.4 driver');
fReg.CloseKey ;
end;
end;

if (not freg.KeyExists('Software\ODBC\ODBC.INI\LMSRPTDATA')) then
result := false
else
result := true; //DSN exists

finally
fReg.Free;
end;
end;


procedure Tdatamod.DataModuleCreate(Sender: TObject);
var fconstr : String;
begin
if fCreateDSN then
begin
with lmsdata do // connection to lms database
begin
Close;
LoginPrompt := false;
fconstr := fReadStrFromIni('Progress','ConnectionString');
ConnectionString := fconstr;
Connected := true;
end;
end; //end if
// lmsdata.Open;
// except on E:Exception do
//// showmessage('Data Module has failed to be initialised' + E.Message);
// end;
end;

procedure CreateDataModule;
begin
try
if not Assigned(datamod) then
DataMod := TDataMod.Create(nil);
except on E:Exception do
// showmessage('Data Module has failed to be initialised' + E.Message);
end;

end;

exports
CreateDataModule;

end.


Calling procedure in main App
=================================

procedure TForm1.Button10Click(Sender: TObject);
var ExecuteChild : TExecuteChild;
// FAdoCon : _Connection;
begin
// CoInitialize(nil);
if lvBPL <> 0 then //if loaded, try locating the ExecuteChild procedure
begin
@ExecuteChild := GetProcAddress(lvBPL,PChar('CreateDataModule'));
if Assigned(ExecuteChild) then
ExecuteChild;
end;

// FAdoCon := datamod.lmsdata.ConnectionObject;
// AV happens here !!!!!
query1.Connection := datamod.lmsdata ;
query1.open;

// CoUninitialize;

end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top