×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

TADOConnection in a Delphi Package

TADOConnection in a Delphi Package

TADOConnection in a Delphi Package

(OP)
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;

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close