Hello (and Happy New Year),
We have a simple function that iterates over the rows of a datawidnow and fill some objects from some of the items in the row. This function looks like the following:
public subroutine fill_recipe_components(datawindow a_dw)
long ll_index, ll_tot
ll_tot = a_dw.rowCount()
for ll_index = 1 to ll_tot
st_recipe_component lst_recipe_component
lst_recipe_component.s_code = a_dw.GetItemString(ll_index, 'article_code_article')
lst_recipe_component.d_percentage = a_dw.GetItemNumber(ll_index, 'pourcentage')
ist_recipe_component[ll_index] = lst_recipe_component
next
end subroutine
We have another function that does exactly the same thing, but on a datastore:
public subroutine fill_recipe_components(datastore a_dw)
long ll_index, ll_tot
ll_tot = a_dw.rowCount()
for ll_index = 1 to ll_tot
st_recipe_component lst_recipe_component
lst_recipe_component.s_code = a_dw.GetItemString(ll_index, 'article_code_article')
lst_recipe_component.d_percentage = a_dw.GetItemNumber(ll_index, 'pourcentage')
ist_recipe_component[ll_index] = lst_recipe_component
next
end subroutine
As one may notice, those functions are strictly identical (to the point we misnamed the datastore parameter a_dw). Is there a way to have a single function instead of 2? It seems like datastore and datawindow are related and have at least a subset of their methods as common interfaces, but the compiler rejects passing one when the other is expected. We tried wrapping a datawindow in a datastore by assigning the dw to the object property of a (new) datastore but this does not work.
datastore n_ds
n_Ds = Create datastore
n_ds.object = <my datawindow>
...
How would wrapping a DS in a DW look like?
I've tried doing something like this:
u_dw ldw_2
datastore lds_temp
any la_data
long ll_i
if apo.typeof() = datawindow! then
messagebox('debug1', "I'm a DataWindow")
ldw_2 = apo
elseif apo.typeof() = datastore! then
messagebox('debug2', "I'm a DataStore")
// now make a datawindow using the passed in datastore object:
ldw_2 = create u_dw
lds_temp = apo
ldw_2.dataobject = lds_temp.dataobject
// ldw_2.settransobject(sqlca)
// la_data = lds_temp.object.data
for ll_i = 1 to lds_temp.rowcount()
ldw_2.insertrow(0)
next
// if not isnull(la_data) then
// ldw_2.object.data = la_data
// end if
//
// if not isnull(la_data) then
// ldw_2.object.data = la_data
// end if
end if
Messagebox('debug4', ldw_2.rowcount())
When passing in a datastore with 3 rows, it correctly assigns the dataobject (can be read back after assignment) and inserts 3 rows, but when you then do a rowcount() it still gives 0 rows.
The commented stuff were other things I tried, but it all fails.
Sorry, seems difficult to be realized.
Instead of doing a CREATE y have to use OpenUserObject.
u_dw is a standard visual object that I made of type 'datawindow' and it's marked as 'invisible' so it doesn't show when I do OpenUserObject.
-----
u_dw ldw_2
datastore lds_temp
any la_data
long ll_i
if apo.typeof() = datawindow! then
messagebox('debug1', "I'm a DataWindow")
ldw_2 = apo
elseif apo.typeof() = datastore! then
messagebox('debug2', "I'm a DataStore")
// now make a datawindow using the passed in datastore object:
openUserobject(ldw_2)
lds_temp = apo
ldw_2.dataobject = lds_temp.dataobject
la_data = lds_temp.object.data
if not isnull(la_data) then
ldw_2.object.data = la_data
end if
end if
Messagebox('debug4', ldw_2.rowcount())
-----
I'll post a sample app in a different answer.