Board index » delphi » porting to new IEnumVARIANT problem

porting to new IEnumVARIANT problem

Please, help me.
I am writing a Delphi application that connects to a COM server and
reads information. The server exposes information via the IEnumVARIANT
interface. I am trying to upgrade to Delphi 5 from Delphi 4. I have
encountered some problems with porting to Delphi 5:

1. I did not find any explanation or example of how to use function
'Next' in the new IEnumVARIANT interface. After much trial and error I
discovered that the following works:

function MyClass.GetRecords(const serverIntf: TServerIntf)
var
 ieRecordSet: IEnumVariant;
 OleVariantsArray: array[0..99] of OleVariant;
 pceltFetched: LongWord;
 i: integer;
 vRecord: OleVariant;
begin
  serverIntf.GetRecordSet(ieRecordSet);
  repeat
    ieRecordSet.Next(100, OleVariantsArray[0], pceltFetched);
//??????????????????
    for i:=0 to pceltFetched-1 do begin
      vRecord:= OleVariantsArray[i];
      //do something with vRecord
    end;
  until pceltFetched = 0;
end;

Can anyone confirm whether this is the correct way to use the Next
function or if there is another way?

2. I am aware of the IEnumVARIANT_D4 interface for backwards
compatiblity. If I wish to keep using this interface instead of the new
IEnumVARIANT interface, is there some way that I can make Delphi apply
this definition when importing type libraries rather than the new
Interface definition?

Please, answer me ASAP, because I am stuck with the porting.

 

Re:porting to new IEnumVARIANT problem


function MyClass.GetRecords(const serverIntf: TServerIntf)
var
   ieRecordSet: IEnumVariant;
   pceltFetched: LongWord;
   vRecord: OleVariant;
begin
  serverIntf.GetRecordSet(ieRecordSet);
  while (ieRecordSet.Next(1, vRecord, pceltFetched) = S_OK) do
  begin
     // do something with vRecord
  end;
end;

--
Rob Lans
Software Engineer
NOB Interactive

Quote
Stas <S...@eventuslog.com> wrote in message

news:388186EA.11679AAD@eventuslog.com...
Quote
> Please, help me.
> I am writing a Delphi application that connects to a COM server and
> reads information. The server exposes information via the IEnumVARIANT
> interface. I am trying to upgrade to Delphi 5 from Delphi 4. I have
> encountered some problems with porting to Delphi 5:

> 1. I did not find any explanation or example of how to use function
> 'Next' in the new IEnumVARIANT interface. After much trial and error I
> discovered that the following works:

> function MyClass.GetRecords(const serverIntf: TServerIntf)
> var
>  ieRecordSet: IEnumVariant;
>  OleVariantsArray: array[0..99] of OleVariant;
>  pceltFetched: LongWord;
>  i: integer;
>  vRecord: OleVariant;
> begin
>   serverIntf.GetRecordSet(ieRecordSet);
>   repeat
>     ieRecordSet.Next(100, OleVariantsArray[0], pceltFetched);
> //??????????????????
>     for i:=0 to pceltFetched-1 do begin
>       vRecord:= OleVariantsArray[i];
>       file://do something with vRecord
>     end;
>   until pceltFetched = 0;
> end;

> Can anyone confirm whether this is the correct way to use the Next
> function or if there is another way?

> 2. I am aware of the IEnumVARIANT_D4 interface for backwards
> compatiblity. If I wish to keep using this interface instead of the new
> IEnumVARIANT interface, is there some way that I can make Delphi apply
> this definition when importing type libraries rather than the new
> Interface definition?

> Please, answer me ASAP, because I am stuck with the porting.

Re:porting to new IEnumVARIANT problem


Stas,

Essentially your code is correct, although i would do something similar to
this:

 function MyClass.GetRecords(const serverIntf: TServerIntf)
 var
  ieRecordSet: IEnumVariant;
  OleVariantsArray: array[0..99] of OleVariant;
  pceltFetched: LongWord;
  i: integer;
  vRecord: OleVariant;
 begin
   serverIntf.GetRecordSet(ieRecordSet);
    while  ieRecordSet.Next(100, OleVariantsArray[0], pceltFetched) = S_OK
do
    begin
         for i:=0 to pceltFetched-1 do begin
           vRecord:= OleVariantsArray[i];
           file://do something with vRecord
         end;
    end;
end;

Nick.

Quote
"Stas" <S...@eventuslog.com> wrote in message

news:388186EA.11679AAD@eventuslog.com...
Quote
> Please, help me.
> I am writing a Delphi application that connects to a COM server and
> reads information. The server exposes information via the IEnumVARIANT
> interface. I am trying to upgrade to Delphi 5 from Delphi 4. I have
> encountered some problems with porting to Delphi 5:

> 1. I did not find any explanation or example of how to use function
> 'Next' in the new IEnumVARIANT interface. After much trial and error I
> discovered that the following works:

> function MyClass.GetRecords(const serverIntf: TServerIntf)
> var
>  ieRecordSet: IEnumVariant;
>  OleVariantsArray: array[0..99] of OleVariant;
>  pceltFetched: LongWord;
>  i: integer;
>  vRecord: OleVariant;
> begin
>   serverIntf.GetRecordSet(ieRecordSet);
>   repeat
>     ieRecordSet.Next(100, OleVariantsArray[0], pceltFetched);
> //??????????????????
>     for i:=0 to pceltFetched-1 do begin
>       vRecord:= OleVariantsArray[i];
>       file://do something with vRecord
>     end;
>   until pceltFetched = 0;
> end;

> Can anyone confirm whether this is the correct way to use the Next
> function or if there is another way?

> 2. I am aware of the IEnumVARIANT_D4 interface for backwards
> compatiblity. If I wish to keep using this interface instead of the new
> IEnumVARIANT interface, is there some way that I can make Delphi apply
> this definition when importing type libraries rather than the new
> Interface definition?

> Please, answer me ASAP, because I am stuck with the porting.

Re:porting to new IEnumVARIANT problem


Sorry Rob - my newsreader seems to be taking forever to refresh, and your
post wasnt up!

Nick.

Quote
"Rob Lans" <rob.l...@nob.nl> wrote in message

news:85v18r$d1o6@bornews.borland.com...
Quote
> function MyClass.GetRecords(const serverIntf: TServerIntf)
> var
>    ieRecordSet: IEnumVariant;
>    pceltFetched: LongWord;
>    vRecord: OleVariant;
> begin
>   serverIntf.GetRecordSet(ieRecordSet);
>   while (ieRecordSet.Next(1, vRecord, pceltFetched) = S_OK) do
>   begin
>      // do something with vRecord
>   end;
> end;

> --
> Rob Lans
> Software Engineer
> NOB Interactive

> Stas <S...@eventuslog.com> wrote in message
> news:388186EA.11679AAD@eventuslog.com...
> > Please, help me.
> > I am writing a Delphi application that connects to a COM server and
> > reads information. The server exposes information via the IEnumVARIANT
> > interface. I am trying to upgrade to Delphi 5 from Delphi 4. I have
> > encountered some problems with porting to Delphi 5:

> > 1. I did not find any explanation or example of how to use function
> > 'Next' in the new IEnumVARIANT interface. After much trial and error I
> > discovered that the following works:

> > function MyClass.GetRecords(const serverIntf: TServerIntf)
> > var
> >  ieRecordSet: IEnumVariant;
> >  OleVariantsArray: array[0..99] of OleVariant;
> >  pceltFetched: LongWord;
> >  i: integer;
> >  vRecord: OleVariant;
> > begin
> >   serverIntf.GetRecordSet(ieRecordSet);
> >   repeat
> >     ieRecordSet.Next(100, OleVariantsArray[0], pceltFetched);
> > //??????????????????
> >     for i:=0 to pceltFetched-1 do begin
> >       vRecord:= OleVariantsArray[i];
> >       file://do something with vRecord
> >     end;
> >   until pceltFetched = 0;
> > end;

> > Can anyone confirm whether this is the correct way to use the Next
> > function or if there is another way?

> > 2. I am aware of the IEnumVARIANT_D4 interface for backwards
> > compatiblity. If I wish to keep using this interface instead of the new
> > IEnumVARIANT interface, is there some way that I can make Delphi apply
> > this definition when importing type libraries rather than the new
> > Interface definition?

> > Please, answer me ASAP, because I am stuck with the porting.

Re:porting to new IEnumVARIANT problem


Thanks, Rob,
but during the optimization circumstances I prefer to call server less times
than number of records... :o)
Stas
Quote
Rob Lans wrote:
> function MyClass.GetRecords(const serverIntf: TServerIntf)
> var
>    ieRecordSet: IEnumVariant;
>    pceltFetched: LongWord;
>    vRecord: OleVariant;
> begin
>   serverIntf.GetRecordSet(ieRecordSet);
>   while (ieRecordSet.Next(1, vRecord, pceltFetched) = S_OK) do
>   begin
>      // do something with vRecord
>   end;
> end;

> --
> Rob Lans
> Software Engineer
> NOB Interactive

> Stas <S...@eventuslog.com> wrote in message
> news:388186EA.11679AAD@eventuslog.com...
> > Please, help me.
> > I am writing a Delphi application that connects to a COM server and
> > reads information. The server exposes information via the IEnumVARIANT
> > interface. I am trying to upgrade to Delphi 5 from Delphi 4. I have
> > encountered some problems with porting to Delphi 5:

> > 1. I did not find any explanation or example of how to use function
> > 'Next' in the new IEnumVARIANT interface. After much trial and error I
> > discovered that the following works:

> > function MyClass.GetRecords(const serverIntf: TServerIntf)
> > var
> >  ieRecordSet: IEnumVariant;
> >  OleVariantsArray: array[0..99] of OleVariant;
> >  pceltFetched: LongWord;
> >  i: integer;
> >  vRecord: OleVariant;
> > begin
> >   serverIntf.GetRecordSet(ieRecordSet);
> >   repeat
> >     ieRecordSet.Next(100, OleVariantsArray[0], pceltFetched);
> > //??????????????????
> >     for i:=0 to pceltFetched-1 do begin
> >       vRecord:= OleVariantsArray[i];
> >       file://do something with vRecord
> >     end;
> >   until pceltFetched = 0;
> > end;

> > Can anyone confirm whether this is the correct way to use the Next
> > function or if there is another way?

> > 2. I am aware of the IEnumVARIANT_D4 interface for backwards
> > compatiblity. If I wish to keep using this interface instead of the new
> > IEnumVARIANT interface, is there some way that I can make Delphi apply
> > this definition when importing type libraries rather than the new
> > Interface definition?

> > Please, answer me ASAP, because I am stuck with the porting.

Other Threads