[PB 4.10B4] Macro/With combination

Just starting out? Need help? Post your questions and find answers here.
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

[PB 4.10B4] Macro/With combination

Post 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"
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post 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
Post Reply