October 7th, 2004, 11:52 AM
dynamic array of TFrame and getting triggered events from the correct frame
I have created a TFrame class which has a Zeos(MySQL) Database, Query, DataSource and DBGrid component in it. Each row of the DBGrid has a button which when clicked, will show the detail view of the record.
The main form will query a table and return a RecordCount and a dynamic array of TFrame will be created at runtime.
I have gotten as far as displaying the form and dynamically created frames at runtime successfully.
However, any DBGrid button clicked always return the record of the particular row of DBGrid in the last frame created shown. ie if I have created an array of Frame_0 to Frame_4 and have clicked a DBGrid button on row 1 of Frame_3, the record returned is row 1 of Frame_4.
How to ensure the events triggered come from the right frame ?
BTW, the application is for web using IntraWeb. I figured maybe the last frame always has focus because it is the last one generated at runtime.
Any ideas or better way of doing this ? I'm very much a novice here
October 8th, 2004, 08:07 AM
not quite sure what you want to achieve with this so a little more explanation is probably necessary....
You are creating a frame for every record which could get very heavy on resources indeed if you have a good number of records....
try looking at master detail tables too as you dont really need a button for every row on your frame but maybe I am getting confused....
send a bit more info and i'll be glad to help.
October 9th, 2004, 08:07 AM
Please refer to the edited codes of my first post
I'll give it a try but please pardon my bad English.
Firstly, it is an Intraweb standalone application that I am building in order to plan and organize patients going for surgery. Our given operating days are two days weekly, normally on Monday and Thursday. (I'm a surgeon by the way) Other teams will have their own patients and different days of surgery.
I have a Master table which have dates of surgery and team in charged.
The first thing is to select the operating dates in a particular month for a particular team. That's the job of qryMaster.
This will return a list of op_dates.
The next task is dynamically built the frame based on this records. The frame has a Query (qryDetail), DataSource and DBGrid component in it. The DBGrid has columns for specific datatypes of the detail table such as patient medical record number (MRN), type of surgery etc as well as a hyperlink as Button which when clicked will show the detail information about the surgery for this patient, at this date, under this team in charged.
qryDetail will have its Param op_date, team_name filled up and will populate DBGrid when it is executed.
TfrmViewDetail has a Query component and needs Param such as patient_mrn and op_id filled up. The values will come from a row of DBGrid which has its action button clicked.
Now I have been successful up to this point with the kind of codes shown above.
The problem :
If the action button is clicked, it will return the correct RowIndex, but Sender is always DBGrid of the last TIWFrame dynamically created.
Supposed my qryMaster return 4 op_dates, 1st, 8th, 15th, 22nd of a month. I will have 4 frames (frames0 to frames3) with a DBGrid in each listing records of those dates. If I want to see the detail of a patient on row 1 of frames1 (which has op_date = 8th), the detail view will show detail of patient at row 1 of NOT frames1 but frames3 !
The Sender : TObject doesn't say which particular frames the DBGrid came from.
Am I making any sense ? I can do it better in PHP but I love the RAD in Delphi so I thought I give it a try with Delphi. Using D7 by the way.
Thank you for your kind help.
October 11th, 2004, 10:51 AM
I think I have an idea.
You have a frame which has a query which is set up as a detail query to the master. Everytime you change the master, the detail query will be updated to display the current record (its a master detail setup, thats what it does) so you are creating all these frames and as the master query record is changing so is the detail table underneath it
this would explain that you will always get the current record the master is pointing to when you view the detail.
Answers to the problem...... number of ways the easiest but not the best is when you create the frame dont make it a detail table make it a normal table but pass it a key field (the field that your detail and master share) and pull out the data from the table in a seperate query and display that in the frame.
Hope that helps.....