December 07, 2019, 11:06:32 pm

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


RESTORE & GETDATA

Started by Andy, September 20, 2018, 04:26:59 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

I'm adding in more functions to the constants search program, but it's getting a bit long winded.

So I've added into the code a string array with all the constant types:

Code Select
string ListOfControls[100]

int NoOfControls = 20
ListOfControls[1]="AppBar"
ListOfControls[2]="Border"
ListOfControls[3]="Button"
ListOfControls[4]="ComboBox"


etc....

But I can't use the string with RESTORE or GETDATA

Code Select
restore ListOfControls[1]


I get Unable to convert string to datablock error (and the same for getdata) as the datablock is BYREF type.

I've tried using a pointer to the string, but I still can't get it to work.

Can it be done with a string?

Thanks,
Andy.
:)



Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Not sure exactly what you are doing, but:
why can't you put the control types in a data block and then just read them into the string in a loop?

that seems so obvious so I have to be missing something
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Now, when I was building IWB+ I didn't know how many controls a form was going to have or how many many flags each control would have.

So what I used was a combination of data blocks for the possibilities for all the flags and such and then used nested linked-lists as I added forms to a project; then controls to a form, then flags to a control.

Maybe that gives you some food for thought for what you are trying to do.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

fasecero

Look at mrainey's answer in this post about string arrays, maybe it can help?
http://www.ionicwind.com/forums/index.php?topic=1650.msg15244#msg15244

billhsln

How about instead of:

Code Select
DATABEGIN ProgressBars
DATA "PBM_DELTAPOS","(WM_USER+3)"
DATA "PBM_GETPOS","(WM_USER+8)"


Do:

Code Select
DATABEGIN Constants
DATA "PROGRESS","PBM_DELTAPOS","(WM_USER+3)"
DATA "PROGRESS","PBM_GETPOS","(WM_USER+8)"


Bill
When all else fails, get a bigger hammer.

fasecero

After a second look I think I understand your question better, it's not a problem of string array as I thought in principle, but a problem of arguments instead.

Code Select
RESTORE (blockname as DATABLOCK BYREF)
GETDATA (blockname as DATABLOCK BYREF, var as ANYTYPE)


"DATABLOCK BYREF" will never accept a string, integer or anything like that as an argument, the only way to do it in the way you want is to use POINTERS instead of names, it's hard for me to explain so I made an example. Even so, this is something that you should probably not use it, its overcomplicating everything, I only post it for "didactic" purposes. I would follow Larry's advice and Bill has shown you an excellent alternative.

Code Select


OPENCONSOLE
PRINT
PrintDatas()

PRINT
PRINT "Press any key to exit"
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE

DECLARE CDECL EXTERN _sprintf(buf as STRING, format as STRING, ...),INT

SUB PrintDatas()
STRING str
INT iDay
pointer p ' pointer to current DATABLOCK

' data's address array
pointer ListOfDatas[3]
ListOfDatas[1]= &mydata1
ListOfDatas[2]= &mydata2

' print mydata1
p = GetDATABLOCK(ListOfDatas[1])
RESTORE(#<datablock>p)
FOR x = 1 to 7
GETDATA #<datablock>p, str
PRINT str
NEXT x

PRINT ""

' print mydata2
p = GetDATABLOCK(ListOfDatas[2])
RESTORE (#<datablock>p)
FOR x = 1 to 7
GETDATA #<datablock>p, iDay
PRINT iDay
NEXT x
ENDSUB

SUB GetDATABLOCK(pointer name), pointer
string temp = ""
_sprintf(temp, "%d", name)
int a = VAL(temp)
pointer p = a + 0
RETURN p
ENDSUB

DATABEGIN mydata1
DATA "monday","tuesday","wednesday","thursday","friday","saturday","sunday"
DATAEND

DATABEGIN mydata2
DATA 1, 2, 3, 4, 5, 6, 7
DATAEND

Andy

Thanks everyone for your replies and emails.

I will check the suggestions out - much appreciated!

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.