views:

65

answers:

1

Hi

I'm converting the following example code to Delphi:

http://msdn.microsoft.com/en-us/library/bb176406%28v=office.12%29.aspx

My code is something like:

var
  vTable, vRow: OleVariant;
begin
....

  while vTable.EndOfTable = False do
  begin
    vRow := vTable.GetNextRow;
    sEmail := vRow['Email1Address'];
    ShowMessage(sEmail);
  end;
end;

The problem is that I need to pass a string index, 'Email1Address', but Delphi gives the error: Incompatible types: Integer and string.

Should I be using a different type of variant?

TIA

+3  A: 

I've taken a look at the Outlook unit generated from a TLB file and it looks like this:

_Row = interface(IDispatch)
    ['{000630D3-0000-0000-C000-000000000046}']
    //snip
    function Item(Index: OleVariant): OleVariant; safecall;
    //snip
  end;

The Row interface has a method Item, which takes an OleVariant. So use this:

sEmail := vRow.Item('Email1Address');

Also take a look at the MSDN help.

The_Fox
Thanks The_Fox. FTR, I did check the Outlook source, but I only have up to Outlook XP, and GetTable wasn't introduced until Outlook 2007.
Xanyx
You can generate those files yourself (I did). Start Delphi, choose Project\Import Type Library, find the Microsoft Outlook 12.0 Object Library, if it isn't there, you can add %programfiles%\Microsoft Office\Office12\msoutl.olb. Check the "Generate Component Wrapper" and specify an unit dir. Now click "Create Unit". An Office_TLB.pas and an Outlook_TLB.pas are generated.
The_Fox
Excellent, thanks
Xanyx