Seite 1 von 1

HBRINT -> Function GetPrinterName( cWindowsDruckerObjekt )

Verfasst: Di, 27. Sep 2022 11:55
von Wolfgang_B
Hallo,
mir ist in der Function -> GetPrinterName( cWindowsDruckerObjekt ) von Huberts Printerklasse nicht klar, warum die " if cPrinterName = NIL" verwendet wird. Aufgrund der Definition ist doch "cPrinterName" immer NIL??

Code: Alles auswählen

function GetPrinterName( cWindowsDruckerObjekt )
   static cPrinterName := NIL
   local oP, aL, i := 0
   
   if cPrinterName = NIL
      oP := XbpPrinter():new()
      if oP = NIL
         MsgBox("Druckerobjekt konnte nicht erzeugt werden","GetPrinterName()")
			USER_LOG("SYS", "Druckerobjekt konnte nicht erzeugt werden", "VWIN_HBDRUCK", "","GetPrinterName()", "" ) 
         quit
      else
         aL := oP:list()
         i := AScan( aL, {|x| lower(x) == lower(cWindowsDruckerObjekt) } )    // genau
         if i = 0
            i := AScan( aL, {|x| lower(cWindowsDruckerObjekt) $ lower(x) } )  // einigermassen, z.B. bei Netzwerkdrucker
         endif
      endif
      if i > 0
         cPrinterName := aL[i]
      else
         MsgBox("Drucker -> "+cDrucker+" konnte nicht gefunden werden ", "GetPrinterName()")
			USER_LOG("SYS", "Drucker -> "+cDrucker+" konnte nicht gefunden werden", "VWIN_HBDRUCK", "","GetPrinterName()", "" ) 
      endif
   endif
   
return cPrinterName

Re: HBRINT -> Function GetPrinterName( cWindowsDruckerObjekt )

Verfasst: Di, 27. Sep 2022 12:31
von UliTs
Wolfgang,

cPrinterName ist als lokale Static-Variable deklariert. Deshalb wird cPrinterName nur 1x initialisiert und nicht etwa bei jedem Aufruf von GetPrintername().

Edit: etwas -> etwa

Re: HBRINT -> Function GetPrinterName( cWindowsDruckerObjekt )

Verfasst: Di, 27. Sep 2022 12:53
von Wolfgang_B
ok, vielen Dank!

Re: HBRINT -> Function GetPrinterName( cWindowsDruckerObjekt )

Verfasst: Di, 27. Sep 2022 12:55
von UliTs
Gern geschehen. Es gibt auch oben rechts den Button "Daumen hoch". Damit kann man sich auf bedanken :D .