Seite 1 von 1

debug Structure

Verfasst: 11.01.2020 21:31
von marcelx
Hallo,

wie kann ich Daten mit structure ausgeben ohne einzelnen zu ausgeben per Debug?

Code: Alles auswählen

Structure _pos
  x.i
  y.i  
EndStructure

Structure _dimension
  w.i
  h.i  
EndStructure

Structure _list
  name.s
  pos.i  
EndStructure

Structure _specifications
  List._list
  pos._pos
  dimension._dimension
  name.s
EndStructure

NewList specifications._specifications()

AddElement(specifications())

With specifications()
  \name = "Test"
  \pos\x = 10
  \pos\y = 20
  \dimension\h = 15
  \dimension\w = 25
  \list\name = "Test list"
  \list\pos = 1
EndWith

Debug specifications()  ???
Gruss
MarcelX

Re: debug Structure

Verfasst: 11.01.2020 21:38
von STARGÅTE
z.B. mit JSON, die Hilfe zeigt hier sogar ein Beispiel wie du es hast:
https://www.purebasic.com/documentation ... cture.html

Re: debug Structure

Verfasst: 11.01.2020 21:41
von #NULL

Code: Alles auswählen

json = CreateJSON(#PB_Any)
InsertJSONList(JSONValue(json), specifications())
Debug ComposeJSON(json, #PB_JSON_PrettyPrint)
FreeJSON(json)

Re: debug Structure

Verfasst: 11.01.2020 21:45
von marcelx
Wunderbar - danke STARGÅTE
das war eine schnelle Antwort

Code: Alles auswählen

  If CreateJSON(0)
    InsertJSONStructure(JSONValue(0), @specifications(), _specifications)
    Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
  EndIf

Re: debug Structure

Verfasst: 11.01.2020 22:42
von marcelx
wie kann ich eine Structure an eine Procedure übergeben?
Ich möchte mit eine allgemeine Procedure strukturierten Daten anzeigen:

Code: Alles auswählen

Procedure debugStr(*adr, str)
  Debug "----------------------"
  If CreateJSON(0)
    InsertJSONStructure(JSONValue(0), *adr, str)
    Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
  EndIf
  Debug "----------------------"   
EndProcedure
debugStr(@specifications(), _specifications)
So funktioniert nicht.
EDIT: so funktioniert - ich hatte _specifications in Hochkomma gesetzt und geht auch nicht

Re: debug Structure

Verfasst: 12.01.2020 04:17
von mk-soft
Das geht leider nicht, da die Strukturen zur Compilerzeit aufgelöst werden.

Mit Macros kann man einiges lösen.

Code: Alles auswählen

Structure sFoo
  iVal.i
  sVal.s
  List ListVal.i()
EndStructure

Macro debugStr(adr, str)
  Debug "----------------------"
  If CreateJSON(0)
    InsertJSONStructure(JSONValue(0), adr, str)
    Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
  EndIf
  Debug "----------------------"   
EndMacro

data1.sfoo

debugStr(data1, sfoo)

Re: debug Structure

Verfasst: 12.01.2020 11:07
von marcelx
Danke mk-soft für die Erläuterung der Hintergrund.
Daran habe ich nicht gedacht.