🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.groupware.lotus-notes.programmer
1 messages
1 total messages Started by Jeffrey Lunger Fri, 12 Oct 2001 14:56
Problems using Lotus Domino COM object with Delphi 6
#12
Author: Jeffrey Lunger
Date: Fri, 12 Oct 2001 14:56
123 lines
4792 bytes
Hello,
 I've been working with the R5 Lotus Domino COM classes through Delphi and
have run into a strange problem. After starting a session, opening the
public address book, grabbing out some data via the 'People' view, shutting
down the session by setting the session and database variables to nil, and
then starting it back up and doing it all again, I get memory access
violations when accessing the items derived from the 'People' view of the
address book. I have duplicated my code in VB and do not see this error
there.
 Attached is my sample app. The form consists of two buttons, one for
starting and the other for stopping the session, and a listbox that serves
as a place to list data found in the address book. Domino_TLB.pas is
generated through Delphi's 'Import Type Libray' utility and uses the
domobj.tlb as its source.
 If anyone out there has encountered this type of problem before and has
some insight or can see something blatantly wring with my code, please let
me know. There does not seem to be much out there about using this COM
object with Delphi, so any help would be greatly appreciated.

Thanks In Advance,
Jeffrey Lunger
jlunger@lawmanager.com

// code follows

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Domino_TLB;

const
  // logon info
  PASSWORD = 'password';
  SERVER = 'server';
  MAILBOX = 'mail\mailbox.nsf';

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    Session: NotesSession;
    NotesDb: NotesDatabase;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// clicking this button initializes a Lotus Notes session, opens a database,
reads
// names out of the public address book, and puts them in the list box
procedure TForm1.Button1Click(Sender: TObject);
var
  AddrBook: NotesDatabase;
  People: NotesView;
  Person: NotesDocument;
  AddrBooks: OleVariant;
  x: Integer;
begin
  try
    if (Session = nil) then
    begin
      Session := CoNotesSession.Create;
      Session.Initialize(PASSWORD);
      NotesDb := Session.GetDatabase(SERVER, MAILBOX, False);
      AddrBooks := Session.AddressBooks;
      // go throught the address books and find the public one
      for x := 0 to VarArrayHighBound(AddrBooks, 1) -
VarArrayLowBound(AddrBooks, 1) do
      begin
        AddrBook := IDatabase(IUnknown(AddrBooks[x]));
        if (AddrBook.IsPublicAddressBook) then
        begin
          AddrBook.Open;
          break;
        end
        else
          AddrBook := nil;
      end;
      // if we have found the public address book, get the People view
      // and list out the FullName items in it
      if (AddrBook <> nil) then
      begin
        People := AddrBook.GetView('People');
        Person := People.GetFirstDocument;
        // go through each entry
        while (Person <> nil) do
        begin
          // this works the first time through, but on the second time
through the
          // IItem interface returned by GetFirstItem will raise an access
          // violation when trying to access the value of its Text property
          ListBox1.Items.Add(Person.GetFirstItem('FullName').Text);
          Person := People.GetNextDocument(Person);
        end;
      end;
    end;
  finally
    AddrBook := nil;
    People := nil;
    Person := nil;
  end;
end;

// clicking this button destroys the Notes objects and clears the list box
procedure TForm1.Button2Click(Sender: TObject);
begin
  ListBox1.Clear;
  Session := nil;
  NotesDb := nil;
end;

end.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads