IonicWind Software

IWBasic => General Questions => Topic started by: Andy on September 20, 2018, 04:26:59 am

Title: RESTORE & GETDATA
Post by: Andy on September 20, 2018, 04:26:59 am
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.
:)



Title: Re: RESTORE & GETDATA
Post by: LarryMc on September 20, 2018, 06:53:05 am
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
Title: Re: RESTORE & GETDATA
Post by: LarryMc on September 20, 2018, 07:01:22 am
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.
Title: Re: RESTORE & GETDATA
Post by: fasecero on September 20, 2018, 10:24:32 am
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
Title: Re: RESTORE & GETDATA
Post by: billhsln on September 20, 2018, 11:09:02 am
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
Title: Re: RESTORE & GETDATA
Post by: fasecero on September 20, 2018, 12:50:39 pm
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
Title: Re: RESTORE & GETDATA
Post by: Andy on September 21, 2018, 09:27:19 am
Thanks everyone for your replies and emails.

I will check the suggestions out - much appreciated!

Andy.
:)