avpatil
30th December 2002, 21:46
Hi,
I have a question. DO I need to use on.main.table() function even if I will read the main table in a DLL. My understanding is I need not use the on.main.table() if I am reading the main table in DLL as it will be a different object.

Thanks

Arvind

NPRao
30th December 2002, 22:16
Arvind,

the function - on.main.table() is mostly used in the multi-occ session with automatic free number generations. You use this function to get the highest number in the unsaved records in the current session.

Please enter your baan/os/database info in your profile.

avpatil
30th December 2002, 22:22
Hi NPRao,
on.main.table() is used to save the current record pointer. If I read the same table I will loose the pointer and hence the record. e.g say I am in sales order header and working in sales order 300001 and say I need to look some other value of say another sales order say 300002. If read the sales Order 300002 directly (without maintable) then I will loose the the first order. This function is obviously not required in type 4 session, but is required in other type if one is reading the same table again. In he example you have mentioned yes, it will be required. My Question is if I read the main table in a DLL will I loose my record or not?

Thanks

Arvind

KlayVessel
2nd January 2003, 07:18
Been a long time since I've been here....

on.main.table() is not used to save the current record pointer - actually it saves the current record (this can be simulated with a based variable, allocating appropriate memory to it, and then storing off and later restoring the rcd.ppmmmttt special record variable).

From the Baan 5 help text:

This copies the contents current record of the main table to the record buffer of that table, saves the record, and executes the specified function. After that the saved record buffer is restored. This enables you to perform actions on the record contents without affecting the values in the table.

This is an important difference as the current contents of the record buffer may not be the current record in the database -- the user may have (and it's highly likely) already modified some of the fields in the record.

And, yes, your table access in the DLL will cause a problem with your session. Actually, all versions of Baan 4 and later, a 4GL session IS a DLL. This happens because:

(1) All table related variables (the t<table>, each field, and all psuedo fields) are automatically declared with "extern".

(2) All "extern" variables of the same name within the same process (within the bshell VM) reference the exact same memory location.

In fact, if the above were not true then the standard program accesses to the main table would not be visible to your 4GL object (again a DLL).

So you do need to use on.main.table() to call your DLL function if you wish to preserve the current contents of the record. Of course, you could do this a number of other ways but all would be more cumbersome (save/restore the individual fields in the table, simulate on.main.table with your own dynamic memory area and save/restore rcd.xxxxxx buffer).

If your DLL function cannot be referenced in on.main.table() since it is non-void (i.e. has parameters) then you will need to wrap that in a local function that is void and then pass the appropriate parameters to the DLL function.