Retrieve the fields from a structure

Just starting out? Need help? Post your questions and find answers here.
thanos
Enthusiast
Enthusiast
Posts: 422
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Retrieve the fields from a structure

Post by thanos »

Hello.
Lets say we define the following structure:

Code: Select all

Structure Invoice
  Code.s
  Date.s
  NetValue.d
  VAT.d
  Total.d
EndStructure
Is it a way to retrieve all fields (name and type) from the above structure?
Such as

Code: Select all

ForEach
go inside all members from a list, map or something like that?
Regards

Thanos
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Retrieve the fields from a structure

Post by #NULL »

You can do something like that with the JSON and XML libs.

similar, but not the exact answer i think, but it was posted somewhere in the forum:
How to loop through structure fields?
https://www.purebasic.fr/english/viewtopic.php?t=73867
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Retrieve the fields from a structure

Post by NicTheQuick »

One idea is to use 'InsertJSONStructure()'. The example in the help will help you with that.

But you also have to know that structures and their fields do not have names anymore after compilation. Another thing which could help you there, would be the keyword "Runtime".
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
thanos
Enthusiast
Enthusiast
Posts: 422
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Re: Retrieve the fields from a structure

Post by thanos »

#NULL wrote: Tue Dec 07, 2021 8:22 pm You can do something like that with the JSON and XML libs.

similar, but not the exact answer i think, but it was posted somewhere in the forum:
How to loop through structure fields?
https://www.purebasic.fr/english/viewtopic.php?t=73867
Thanks for your reply!
It is not the exact answer but the solution is smart (as was expected for infratec's code).
I try to add the JSONType() and it might be the solution I was looking for.
Regards
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
thanos
Enthusiast
Enthusiast
Posts: 422
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Re: Retrieve the fields from a structure

Post by thanos »

NicTheQuick wrote: Tue Dec 07, 2021 8:56 pm One idea is to use 'InsertJSONStructure()'. The example in the help will help you with that.

But you also have to know that structures and their fields do not have names anymore after compilation. Another thing which could help you there, would be the keyword "Runtime".
You are right.
I will try it
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Retrieve the fields from a structure

Post by mk-soft »

JSONType tries to recognise the type of the data, but cannot recognise the type of your structure.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply