You rarely create a CDX, you create a tag in the main CDX of a table, you create this main CDX when you issue the first INDEX ON expression TAG tagname for a DBF or create the first index in the table designer.
And the only thing that's special about using a function in an index expression is, that SET PROCEDURE must make this function available, or usage of the CDX gets in trouble. Remember the main CDX of a table will be maintained automatically. If you update data or insert a new record all tags of the main CDX will need an update and for that to work the Hierarchy function must be visible to VFP. Besides that specialty for indexes based on user-defined functions, there is nothing special about updating a table which has a cdx besides perhaps also an fpt, you only USE the DBF, any memo like fields automatically go into the fpt and any index changes due to data changes automatically go into the CDX. For this to be possible in case an index expression uses a function, well, as already said, VFP must know where to find that to be able to call it.
I guess the problem is somewhere here.
You can create secondary CDXes when you use the OF CDXFilename clause of the INDEX command, but I doubt you do. Then there can be any number of additional IDX files, but they play no role anymore, could be used for temp indexes, but I doubt that you use the hierarchy only temporary and that you put this in an extra idx or cdx. Do you?
As Mike already said, you don't actually show the code creating an index (tag), you just show the function used in the index expression. I remember this was in a lengthy recent thread, not more than a month old. It won't matter, but what matters is, that you got some wrong ideas here about how indexes work, it seems. The only reason you would put that into an extra CDX I see as possible is, that this index is larger than usual tags. Though I remember we made it some C(5) at max for each node, wasn't it in that regime? Then you're far below something even as simple as an index on a char(20) field, for example, for which you also wouldn't create an extra CDX file, so size isn't the issue. The only other reason would be to not depend on SET PROCEDURE to be configured correctly every time you use the dbf. The index then won't update automatically, though, just like IDX index files need to be open/set to update together with table data changes. So it's not a good reason.
I think besides that function, you got INDEX ON hierarchy(keyfield) TAG tagname or something like that. And, well, that's something you only do once, then this index tag is part of your table like any field is, just like you don't ALTER TABLE ADD COLUMN every time you use a table, you also don't INDEX ON anymore, once an index is established, you only use it from then on. The only added dependency with an index expression calling self-defined function is, that this function must be visible when you work in the DBF.
Bye, Olaf.
Olaf Doschke Software Engineering