Board index » delphi » stupid stupid stupid question: Notes OLE

stupid stupid stupid question: Notes OLE

I find that I can access Lotus Notes fine from Delphi 5 by adding ComObj
and using CreateOLEObject, but I am obviously missing some important
understanding of what is happening.  The code below works fine as long
as I hand it a valid view name in eView.Text but gives an error when I
try to access the nonexistent object returned when I give it an invalid
view name.  The error shows up of course in view.GetFirstDocument
because view points to FFFFFFFF.

How do I go about testing the success or failure of the assignment?  
In Perl the value of an assignment returns a boolean so I can say:
if ( view := nsf.GetView(eView.Text) )
   { do something with view }
else
   { error recovery }
... How do I do something like this with Delphi?  I tried comparing the
variant view with Nil and Null and Unassigned and they are all not valid
variant conversions.  I know there must be some way to do this but I
have not been able to see it.  Any help would be appreciated.
-Dan
=========== code sample =====================================
form with a TListBox called OrderList and a TButton called bReload
{in Uses add ComObj}
=============================================================
procedure TForm1.bReloadClick(Sender: TObject);
var view, nsf, session, notesdoc, newnotesdoc, lastnotesdoc: variant;
    DocDescription, DocNumber, LastDocNumber: String;
begin
   OrderList.Clear;
   {Load headlines from Notes}
   session := CreateOLEObject('Notes.NotesSession');

   nsf := Session.GetDatabase('Dev/TaxBed/US','test\kpbdocno.nsf');
   {Need some way to check these!!!}
   view := nsf.GetView(eView.Text);
   notesdoc := view.GetFirstDocument;
   lastnotesdoc := view.GetLastDocument;
   LastDocNumber := lastnotesdoc.GetItemValue('docno')[0];

   DocDescription := notesdoc.GetItemValue('docdescr')[0];
   DocNumber := notesdoc.GetItemValue('docno')[0];
   OrderList.Items.Add(DocNumber+': '+DocDescription);
   while ( DocNumber <> LastDocNumber  )
      do
      begin
         newnotesdoc := view.GetNextDocument(notesdoc);
         notesdoc := newnotesdoc;
         DocDescription := notesdoc.GetItemValue('docdescr')[0];
         DocNumber := notesdoc.GetItemValue('docno')[0];
         OrderList.Items.Add(DocNumber+': '+DocDescription);
      end;

end;

 

Re:stupid stupid stupid question: Notes OLE


What does VarType (View) return after calling an invalid view name?

have fun
--
Binh Ly
http://www.techvanguards.com

Quote
"Dan Barlow" <danbar...@radix.net> wrote in message

news:3A26E9C9.D41C4861@radix.net...
Quote
> I find that I can access Lotus Notes fine from Delphi 5 by adding ComObj
> and using CreateOLEObject, but I am obviously missing some important
> understanding of what is happening.  The code below works fine as long
> as I hand it a valid view name in eView.Text but gives an error when I
> try to access the nonexistent object returned when I give it an invalid
> view name.  The error shows up of course in view.GetFirstDocument
> because view points to FFFFFFFF.

> How do I go about testing the success or failure of the assignment?
> In Perl the value of an assignment returns a boolean so I can say:
> if ( view := nsf.GetView(eView.Text) )
>    { do something with view }
> else
>    { error recovery }
> ... How do I do something like this with Delphi?  I tried comparing the
> variant view with Nil and Null and Unassigned and they are all not valid
> variant conversions.  I know there must be some way to do this but I
> have not been able to see it.  Any help would be appreciated.
> -Dan
> =========== code sample =====================================
> form with a TListBox called OrderList and a TButton called bReload
> {in Uses add ComObj}
> =============================================================
> procedure TForm1.bReloadClick(Sender: TObject);
> var view, nsf, session, notesdoc, newnotesdoc, lastnotesdoc: variant;
>     DocDescription, DocNumber, LastDocNumber: String;
> begin
>    OrderList.Clear;
>    {Load headlines from Notes}
>    session := CreateOLEObject('Notes.NotesSession');

>    nsf := Session.GetDatabase('Dev/TaxBed/US','test\kpbdocno.nsf');
>    {Need some way to check these!!!}
>    view := nsf.GetView(eView.Text);
>    notesdoc := view.GetFirstDocument;
>    lastnotesdoc := view.GetLastDocument;
>    LastDocNumber := lastnotesdoc.GetItemValue('docno')[0];

>    DocDescription := notesdoc.GetItemValue('docdescr')[0];
>    DocNumber := notesdoc.GetItemValue('docno')[0];
>    OrderList.Items.Add(DocNumber+': '+DocDescription);
>    while ( DocNumber <> LastDocNumber  )
>       do
>       begin
>          newnotesdoc := view.GetNextDocument(notesdoc);
>          notesdoc := newnotesdoc;
>          DocDescription := notesdoc.GetItemValue('docdescr')[0];
>          DocNumber := notesdoc.GetItemValue('docno')[0];
>          OrderList.Items.Add(DocNumber+': '+DocDescription);
>       end;

> end;

Re:stupid stupid stupid question: Notes OLE


Quote
Binh Ly wrote:

> What does VarType (View) return after calling an invalid view name?

> have fun
> --

Unfortunately, it returns 9 (varDispatch) whether it worked or not.
However, I found the related VarIsEmpty(View) which does what I want.
Thank you for the help!  :)
-Dan

Re:stupid stupid stupid question: Notes OLE


Dan,

Have you had any success automating Lotus 123?

A friend is desperate!

Personally I use office exclusively

Thanx,

Greg

Quote
Dan Barlow <danbar...@radix.net> wrote in message

news:3A27FB3E.C8DC7E29@radix.net...
Quote
> Binh Ly wrote:

> > What does VarType (View) return after calling an invalid view
name?

> > have fun
> > --

> Unfortunately, it returns 9 (varDispatch) whether it worked or not.
> However, I found the related VarIsEmpty(View) which does what I
want.
> Thank you for the help!  :)
> -Dan

Other Threads