Recent

Author Topic: I have a problem with porting VBA code to Lazarus - OleVariant enumeration  (Read 2602 times)

Sylwester

  • Newbie
  • Posts: 4
Code VBA

Quote
Sub ListaDokumentow()
On Error GoTo ErrHandler
   
    Dim oSubGT As InsERT.Subiekt
    Dim oListaDok As InsERT.SuDokumentyLista
    Dim oDok As InsERT.SuDokument
    Dim sNapis As String
       
    Set oSubGT = UruchomSubiekta()
     
 
    Set oListaDok = oSubGT.Dokumenty.Wybierz()
    oListaDok.FiltrTypOpcje = gtaFiltrSuDokumentOpcjeZam
    oListaDok.FiltrTyp = gtaFiltrSuDokumentZam
    oListaDok.FiltrOkres = gtaFiltrOkresNieokreslony
    oListaDok.MultiSelekcja = True
   
    oListaDok.Wyswietl
   
    sNapis = "Zaznaczono nastęujące dokumenty: " & vbCrLf
   
    For Each oDok In oListaDok.ZaznaczoneDokumenty
        sNapis = sNapis & oDok.NumerPelny & "ID:" & oDok.Identyfikator & vbCrLf
       
    Next
   
    MsgBox sNapis
   
   
    Exit Sub
ErrHandler:
    MsgBox "Wystąpił błąd: " & Err.Number & " - " & Err.Description
   
End Sub

and code LAZARUS

Quote
unit sm_testy;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, wps_u, LCLType,Comobj,variants,ActiveX;

type
  TOleCollectionEnumClass = class(TObject);
  TEkSmTesty = class(TForm)
  private

  public

  end;

var
  EkSmTesty: TEkSmTesty;

implementation

{$R *.lfm}


var
aSubGT,oSubGT:OleVariant;
oListGT,gtaFiltrOkresNieokreslony,gtaFiltrSuDokumentOpcjeZam,gtaFiltrSuDokumentZam:OleVariant;
oDok: OleVariant;
Reply, BoxStyle: Integer;

begin

BoxStyle := MB_ICONQUESTION + MB_YESNO;
//Reply := Application.MessageBox(PChar(IntToStr(PROG_VER_NUM_RC)),'Test', BoxStyle);

wpsConnect(oSubGT,true);

oListGT:=oSubGT.Dokumenty.Wybierz;
oListGT.FiltrTypOpcje:=15;
//oListGT.FiltrTyp:=gtaFiltrSuDokumentZam;
oListGT.FiltrOkres:=gtaFiltrOkresNieokreslony;
oListGT.MultiSelekcja:= True;
oListGT.Wyswietl;

end. // eof
                         


I can't make a loop to enumerate OleVariant - oListGT. MarkedDocuments What to do to get to the value oDok
« Last Edit: February 17, 2022, 02:04:30 pm by Sylwester »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Have a look at https://www.stack.nl/~marcov/wmishowwinver.zip and the unit wmiutil in there. (and the other file demonstrates)

It allows to do olevariant enum with for..in
« Last Edit: February 18, 2022, 09:43:04 am by marcov »

Sylwester

  • Newbie
  • Posts: 4
This link not working - please send by google drive or other.

Thaddy

  • Hero Member
  • *****
  • Posts: 14200
  • Probably until I exterminate Putin.
The link does not work indeed. May be just https ?
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Corrected the link

Sylwester

  • Newbie
  • Posts: 4
Not working link - please correct this  becouse is important for me.

WooBean

  • Full Member
  • ***
  • Posts: 229
First shot "delphi iterate enumeration" in Google service  leads us to https://stackoverflow.com/questions/1600575/iterate-through-items-in-an-enumeration-in-delphi/1600600 where you can find:
Code: Pascal  [Select][+][-]
  1. type
  2.   TWeekdays = (wdMonday, wdTuesday, wdWednesday, wdThursday, wdFriday);
  3.  
  4. procedure Test;
  5. var
  6.   el: TWeekdays;
  7. begin
  8.   for el := Low(TWeekdays) to High(TWeekdays) do
  9.     ; //
  10. end;
  11.  

Is it enough?
Platforms: Win7/64, Linux Mint Ulyssa/64

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Is it enough?

It is about enumerating an olevariant, not an enumerate an enumeration. IOW different type. Note that my link afaik also works with delphi

paweld

  • Hero Member
  • *****
  • Posts: 970
Best regards / Pozdrawiam
paweld

Sylwester

  • Newbie
  • Posts: 4
It is working good - super - thanks ;)


for oDok in oEnum.Enumerate(oListGT.ZaznaczoneDokumenty) do
    ShowMessage(VarToStr(oDok.Identyfikator));   

 

TinyPortal © 2005-2018