#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Malaysia
    Posts
    4
    Rep Power
    0

    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

    EDITED

    Code :

    // Main Form

    type
    TfrmOTList = class(TIWAppForm)
    qryMaster: TZQuery;
    procedure DoSomething(Sender: TObject; RowIndex : Integer; ColumnIndex : Integer);
    .................
    public
    private
    myframe : array of TIWFrame;
    end;

    procedure TfrmOTList.IWAppFormCreate(Sender: TObject);
    ...
    begin

    { qryMaster has SQL = 'SELECT op_date from op_table where team_name = :team_name and op_month = :current_month' }

    qryMaster.ParamByName('team_name').AsString := Selected Team;
    qryDetail.ParamByName('current_month').AsDate := Selected_Month;

    qryMaster.Open;

    { This query will return 4 to 10 records of op_date }

    SetLength(myframe, qryMaster.RecordCount);

    For I := 0 to qryMaster.RecordCount-1 do
    begin
    myframe := TIWFrame.Create(self);
    with myframe do
    begin
    Name := 'frames' + IntToStr(I);

    .....

    { based on the param op_date returned by qryMaster, the detail query will list specific the records }

    qryDetail.ParamByName('op_date').AsDate := qryMaster.FieldValues['opstatus_date'];
    qryDetail.ParamByName('team_name').AsDate := SelectedDate;

    qryDetail.Open;

    { TIWFrame has a DBGrid tied to qryDetail, and on each row, it has a hyperlink as an action button. If clicked, the button will send Sender:TObject, RowIndex : Integer as the particular row clicked , as well as ColumnIndex. But what I need is just RowIndex}

    DBGrid.OnButtonClick := doSomething;

    Show;

    { loop through all qryMaster records }

    qryMaster.Next;
    end;
    end;

    procedure TfrmOTList.DoSomething(Sender: TObject; RowIndex : Integer; ColumnIndex : Integer);
    begin

    { each column will represent a different DataField of qryDetail. RowIndex will indicate the particular record of interest }

    UserSession.patient_MRN := TTIWDBAdvWebGrid(Sender).CellValues[0, RowIndex];
    UserSession.op_id := StrToInt(TTIWDBAdvWebGrid(Sender).CellValues[2, RowIndex]);
    UserSession.opstatus_id := StrToInt(TTIWDBAdvWebGrid(Sender).CellValues[3, RowIndex]);
    UserSession.sql_mode := 'view';
    TfrmViewDetail.Create(WebApplication).Show;
    end;

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    32
    Rep Power
    10
    Hi there,

    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.

    Mox.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Malaysia
    Posts
    4
    Rep Power
    0
    Please refer to the edited codes of my first post

    Hi again,

    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    32
    Rep Power
    10
    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.....

IMN logo majestic logo threadwatch logo seochat tools logo