Page 1 of 1

[PB 4.10B4] Macro/With combination

Posted: Wed Oct 10, 2007 11:25 am
by Progi1984

Code: Select all

;{ Macros
  Macro DQuote
    "
  EndMacro
  Macro ListView_Add(Flag)
    Item.l = CountGadgetItems(0)
    AddGadgetItem(0, Item, DQuote#Flag#DQuote)
    If \ID = #True : SetGadgetItemState(#Main_ListView_0, Item, #True) : EndIf
  EndMacro
;}
;{ Structures
  Structure Test
    ID.l
  EndStructure
;}

Global *Infos.Test
*Infos\ID = #True

If OpenWindow(0,0,0,270,140,"ListViewGadget",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ListViewGadget(0,10,10,250,120)
  For a=1 To 12
    With *Infos
      ListView_Add(a)
    EndWith
  Next
  SetGadgetState(0,9)
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Test this code, I have an error of "Line 24 : Syntax error"

Posted: Wed Oct 10, 2007 5:03 pm
by ABBKlaus
according to the docs With is a macro and therefore cannot be nested.
With : EndWith block allows to reduce the amount of code to type and ease its readibility when using a lot of structure fields. It contains regular PureBasic code, and automatically inserts the specified expression before any anti-slash '\' character which does have a space or an operator before it. This is a compiler directive, and works like a macro: the line is expanded at compile time. With : EndWith blocks can not be nested, as it could introduce hard to track bugs, when having several implicitely replaced statement with different values.
Regards Klaus