Board index » delphi » Problem with initialising normal objects inside OLE wrappers

Problem with initialising normal objects inside OLE wrappers

I am having problems writing a wrapper for a fully operational package of
LDAP routines...

Everything works fine (Open and Close work fine) until I try and call the
IuqConn.Search routine, which returns a IuqEntryList object.

function TuqConn.Search(SearchBase, Query, Scope: PChar): IuqEntryList;
begin
/// the following line does work, and does call the Initialise routine
  Result:=TuqEntryList.Create;
/// However, by the time I get here the TUqEntryList(Result).fEntryList
/// is nil, even though the above initialise routine did actually create it.
  fConn.Search(TUqEntryList(Result).fEntryList,SearchBase,Query,Scope);
end;

Any hints would be appreciated... it is the first time I have tried to share
code between normal and Automation objects.

Details of classes below (ldapConnection and ldapEntryList are normal object
classes which are tested and work).

****************************
Type library declarations

// *********************************************************************//
// Interface: IuqConn
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {31AA013C-01D2-4D18-A3C9-C5AAC77717D7}
// *********************************************************************//
  IuqConn = interface(IDispatch)
    ['{31AA013C-01D2-4D18-A3C9-C5AAC77717D7}']
    procedure Close; safecall;
    function Search(SearchBase: PChar; Query: PChar; Scope: PChar):
IuqEntryList; safecall;
    procedure Open(Host: PChar; Port: SYSINT; BindDN: PChar; Password:
PChar); safecall;
  end;

// *********************************************************************//
// DispIntf:  IuqConnDisp
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {31AA013C-01D2-4D18-A3C9-C5AAC77717D7}
// *********************************************************************//
  IuqConnDisp = dispinterface
    ['{31AA013C-01D2-4D18-A3C9-C5AAC77717D7}']
    procedure Close; dispid 202;
    function Search(SearchBase: {??PChar}OleVariant; Query: {??PChar}
OleVariant;
                    Scope: {??PChar}OleVariant): IuqEntryList; dispid 203;
    procedure Open(Host: {??PChar}OleVariant; Port: SYSINT; BindDN: {??PChar}
OleVariant;
                   Password: {??PChar}OleVariant); dispid 201;
  end;
// *********************************************************************//
// Interface: IuqEntryList
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {391B4B62-C2F8-480C-B7E1-7E2EC0BABC1B}
// *********************************************************************//
  IuqEntryList = interface(IDispatch)
    ['{391B4B62-C2F8-480C-B7E1-7E2EC0BABC1B}']
    function Get_DN(Index: Integer): PChar; safecall;
    function Get_Entry(Index: Integer): IuqEntry; safecall;
    function Get_Count: Integer; safecall;
    property DN[Index: Integer]: PChar read Get_DN;
    property Entry[Index: Integer]: IuqEntry read Get_Entry;
    property Count: Integer read Get_Count;
  end;

// *********************************************************************//
// DispIntf:  IuqEntryListDisp
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {391B4B62-C2F8-480C-B7E1-7E2EC0BABC1B}
// *********************************************************************//
  IuqEntryListDisp = dispinterface
    ['{391B4B62-C2F8-480C-B7E1-7E2EC0BABC1B}']
    property DN[Index: Integer]: {??PChar}OleVariant readonly dispid 204;
    property Entry[Index: Integer]: IuqEntry readonly dispid 201;
    property Count: Integer readonly dispid 202;
  end;

****************************
My declarations

  TuqConn = class(TAutoObject, IuqConn)
  private
    fConn:ldapConnection;
  protected
    procedure Open(Host: PChar; Port: SYSINT; BindDN: PChar; Password:
PChar); safecall;
    procedure Close; safecall;
    function Search(SearchBase, Query, Scope: PChar): IuqEntryList; safecall;
  public
    procedure Initialize; override;
    destructor Destroy; override;
  end;

  TuqEntryList  = class(TAutoObject, IuqEntryList)
  private
    fEntryList:ldapEntryList;
  protected
    { Protected declarations }
  public
    procedure Initialize; override;
    destructor Destroy; override;
  end;

(*  CONN *)

procedure TuqConn.Close;
begin
  LogMsg('uqConn Close');
  fConn.Close;
end;

destructor TuqConn.Destroy;
begin
  LogMsg('uqConn Destroy');
  try
    fConn.Free;
  finally
    inherited;
  end;
end;

procedure TuqConn.Initialize;
begin
  LogMsg('uqConn Initialise');
  inherited;
  fConn:=ldapConnection.Create;
end;

procedure TuqConn.Open(Host: PChar; Port: SYSINT; BindDN, Password: PChar);
begin
  fConn.Open(Host,BindDN,Password,FALSE,Port);
end;

function TuqConn.Search(SearchBase, Query, Scope: PChar): IuqEntryList;
begin
  Result:=TuqEntryList.Create;
  fConn.Search(TUqEntryList(Result).fEntryList,SearchBase,Query,Scope);
end;

(*  ENTRYLIST *)

procedure TuqEntryList.Initialize;
begin
  inherited;
  fEntryList:=ldapEntryList.Create;
end;

destructor TuqEntryList.Destroy;
begin
  fEntryList.Free;
  inherited;
end;

--
---
/* Christopher Burke - Spam Mail to craz...@hotmail.com
|* www.craznar.com -
\* Real mail to cburke(at)craznar(dot)com

 

Re:Problem with initialising normal objects inside OLE wrappers


Quote
Christopher Burke wrote:
> I am having problems writing a wrapper for a fully operational package of
> LDAP routines...

> Everything works fine (Open and Close work fine) until I try and call the
> IuqConn.Search routine, which returns a IuqEntryList object.

> function TuqConn.Search(SearchBase, Query, Scope: PChar): IuqEntryList;
> begin
> /// the following line does work, and does call the Initialise routine
>   Result:=TuqEntryList.Create;
> /// However, by the time I get here the TUqEntryList(Result).fEntryList
> /// is nil, even though the above initialise routine did actually create it.
>   fConn.Search(TUqEntryList(Result).fEntryList,SearchBase,Query,Scope);
> end;

Christopher,

This is very much a random shot in the dark, but does replacing the
first line of code with the following fix your problem?

  Result:=TuqEntryList.Create as IUqEntryList;
  ...

Regards,
Scott

Re:Problem with initialising normal objects inside OLE wrappers


Scott Maskiel <scott_mask...@somedomain.com.au> wrote in news:3df6fbd5
@newsgroups.borland.com:

Quote
> Christopher,

> This is very much a random shot in the dark, but does replacing the
> first line of code with the following fix your problem?

>   Result:=TuqEntryList.Create as IUqEntryList;

No ... result is still the same (the private object is still unassigned, even
after having been created).

--
---
/* Christopher Burke - Spam Mail to craz...@hotmail.com
|* www.craznar.com -
\* Real mail to cburke(at)craznar(dot)com

Re:Problem with initialising normal objects inside OLE wrappers


Quote
Christopher Burke wrote:
> Scott Maskiel <scott_mask...@somedomain.com.au> wrote in news:3df6fbd5
> @newsgroups.borland.com:

> No ... result is still the same (the private object is still unassigned, even
> after having been created).

Hi Christopher,

That was one of the silliest responses I have ever made.  My abject
apologies.  I've now taken the time to look at your code and have a few
questions.  I'm happy to take a look at this since I'm in the midst of
implementing something similar here (in terms of structure, not in
functionality) and haven't run into this kind of problem yet.

1. Where is the object factory for your IUQConn interface, and for that
matter the IUQEntryList interface?
2. Your implementation of IUQEntryList doesn't include the methods as
listed in the interface.
3. Why is IUQEntry is undefined in this unit?
4. Why are your implementation of the IUQConn methods in the protected
section of TUQConn?

Regards,
Scott

Re:Problem with initialising normal objects inside OLE wrappers


Scott Maskiel <scott_mask...@somedomain.com.au> wrote in news:3df712b3$1
@newsgroups.borland.com:

Quote
> 1. Where is the object factory for your IUQConn interface, and for that
> matter the IUQEntryList interface?

Not to sure what you mean exactly...

Quote
> 2. Your implementation of IUQEntryList doesn't include the methods as
> listed in the interface.

Yes... I tried to only include the specific code that was relevant to the
problem at hand.

Quote
> 3. Why is IUQEntry is undefined in this unit?

Beause all three of these interfaces tie together

Quote
> 4. Why are your implementation of the IUQConn methods in the protected
> section of TUQConn?

That is where the wizard put them.

The big problem I am having is just extracting the private TOBject descendant
pointer from an IuqEntrylist object, to pass to the base (non-OLE) routine
(fConn.Search).

--
---
/* Christopher Burke - Spam Mail to craz...@hotmail.com
|* www.craznar.com -
\* Real mail to cburke(at)craznar(dot)com

Re:Problem with initialising normal objects inside OLE wrappers


Quote
Christopher Burke wrote:
> Scott Maskiel <scott_mask...@somedomain.com.au> wrote in news:3df712b3$1
> @newsgroups.borland.com:

>>1. Where is the object factory for your IUQConn interface, and for that
>>matter the IUQEntryList interface?

> Not to sure what you mean exactly...

Any object descended from TAutoObject must provide an object factory in
order to create an instance of that object.  How are you creating your
instances of TUqConn?  I'm trying to recreate your problem but can't
because your code won't compile - and if I bodge it to compile it then
won't run..

Which version of Delphi are you working in?

Regards,
Scott

Re:Problem with initialising normal objects inside OLE wrappers


Scott Maskiel <scott_mask...@somedomain.com.au> wrote in news:3df71893$1
@newsgroups.borland.com:

Quote
> Any object descended from TAutoObject must provide an object factory in
> order to create an instance of that object.  How are you creating your
> instances of TUqConn?  I'm trying to recreate your problem but can't
> because your code won't compile - and if I bodge it to compile it then
> won't run..

> Which version of Delphi are you working in?

Version 7..... I can send you full source if you want... in Binaries in a few
minutes.

--
---
/* Christopher Burke - Spam Mail to craz...@hotmail.com
|* www.craznar.com -
\* Real mail to cburke(at)craznar(dot)com

Re:Problem with initialising normal objects inside OLE wrappers


Never mind, just saw it in attachments.

Re:Problem with initialising normal objects inside OLE wrappers


Quote
Christopher Burke wrote:
> Scott Maskiel <scott_mask...@somedomain.com.au> wrote in news:3df71893$1
> @newsgroups.borland.com:

> Version 7..... I can send you full source if you want... in Binaries in a few
> minutes.

Christopher,

Go ahead.. I've got nothing more to look forward to than documentation
right now anyway, so a quick break is more than welcome.

Replace 'somedomain' in my email address with 'nemmco'.

Regards,
Scott

Re:Problem with initialising normal objects inside OLE wrappers


Quote
Christopher Burke wrote:
> Scott Maskiel <scott_mask...@somedomain.com.au> wrote in news:3df71893$1
> @newsgroups.borland.com:

> Version 7..... I can send you full source if you want... in Binaries in a few
> minutes.

Christopher,

This is crazy.  This will not compile in D7, and I can't see how it ever
had a chance to.  Unit1 references TUqConn and TUqEntryList, but doesn't
use any unit that declares these types.

They would normally be declared in the TLB file, but are not in this
case.  Did you send the correct source?

Regards,
Scott

Re:Problem with initialising normal objects inside OLE wrappers


Quote
Christopher Burke wrote:
> Scott Maskiel <scott_mask...@somedomain.com.au> wrote in news:3df71893$1
> @newsgroups.borland.com:

>>Any object descended from TAutoObject must provide an object factory in
>>order to create an instance of that object.  How are you creating your
>>instances of TUqConn?  I'm trying to recreate your problem but can't
>>because your code won't compile - and if I bodge it to compile it then
>>won't run..

>>Which version of Delphi are you working in?

> Version 7..... I can send you full source if you want... in Binaries in a few
> minutes.

Never mind, I see what you're doing..

DLL must be compiled and then type library created, blah blah..

Other Threads