This started out as a question for the Version four forum, but as I formulated my question I produced a lead to the answer. It opens the door a little more on the coding of operations.
--------------------------------------------
Question:
---------
How do you code operations such as a join when the table you wish to use is open in a form view?
Code for a join looks like
a_tbl = table.open("Master.dbf")
join.t_db = "Transaction.dbf"
join.o_file = "Output.dbf"
join.m_key = "master key expression"
join.t_key = "transaction key expression"
join.m_filter = ""
join.t_filter = ""
join.m_count = 2
join.delete_o_dd = .F.
join.m_field1 = "Master->field_name"
join.m_field2 = "transaction->field_name"
a_tbl.join()
a_tbl = table.close()
if the Master.dbf is open this code will generate an error as the line
a_tbl = table.open("Master.dbf")
will NOT create the correct pointer. It will point to a new session called Master1 or somesuch.
What is needed is to dynamically figure what the current name of the reference for the master table will be such that the line
join.m_field1 = "Master->field_name"
can be created with the correct reference
Then, will we need to do something similar for the transaction table?
The answer is to use
master = a_tbl.Name_Get() to get the correct reference
Code for the join tnen looks like
a_tbl = table.open("Master.dbf")
master = a_tbl.Name_Get() 'get the correct reference
join.t_db = "Transaction.dbf"
join.o_file = "Output.dbf"
join.m_key = "master key expression"
join.t_key = "transaction key expression"
join.m_filter = ""
join.t_filter = ""
join.m_count = 2
join.delete_o_dd = .F.
join.m_field1 = master+"->field_name" 'use the correct reference
join.m_field2 = "transaction->field_name"
a_tbl.join()
a_tbl = table.close()
And you do not need to do anything about the transaction table.
Incidentally I created the code for the operation by running a saved operation with the script recorder on, and the script recorder options set to low level xbasic commands. I then simply cut and paste it and ran it. It crashed when run from a button on the form based on the master table so I would close the form and run it from a form on my start table. Not very satisfying.
This way works great.
--------------------------------------------
Question:
---------
How do you code operations such as a join when the table you wish to use is open in a form view?
Code for a join looks like
a_tbl = table.open("Master.dbf")
join.t_db = "Transaction.dbf"
join.o_file = "Output.dbf"
join.m_key = "master key expression"
join.t_key = "transaction key expression"
join.m_filter = ""
join.t_filter = ""
join.m_count = 2
join.delete_o_dd = .F.
join.m_field1 = "Master->field_name"
join.m_field2 = "transaction->field_name"
a_tbl.join()
a_tbl = table.close()
if the Master.dbf is open this code will generate an error as the line
a_tbl = table.open("Master.dbf")
will NOT create the correct pointer. It will point to a new session called Master1 or somesuch.
What is needed is to dynamically figure what the current name of the reference for the master table will be such that the line
join.m_field1 = "Master->field_name"
can be created with the correct reference
Then, will we need to do something similar for the transaction table?
The answer is to use
master = a_tbl.Name_Get() to get the correct reference
Code for the join tnen looks like
a_tbl = table.open("Master.dbf")
master = a_tbl.Name_Get() 'get the correct reference
join.t_db = "Transaction.dbf"
join.o_file = "Output.dbf"
join.m_key = "master key expression"
join.t_key = "transaction key expression"
join.m_filter = ""
join.t_filter = ""
join.m_count = 2
join.delete_o_dd = .F.
join.m_field1 = master+"->field_name" 'use the correct reference
join.m_field2 = "transaction->field_name"
a_tbl.join()
a_tbl = table.close()
And you do not need to do anything about the transaction table.
Incidentally I created the code for the operation by running a saved operation with the script recorder on, and the script recorder options set to low level xbasic commands. I then simply cut and paste it and ran it. It crashed when run from a button on the form based on the master table so I would close the form and run it from a form on my start table. Not very satisfying.
This way works great.