Help with processing Event for the component created in the RunTime mode.

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
AlexMik
Posts: 6
Joined: Wed 26 Dec 2007 19:23

Help with processing Event for the component created in the RunTime mode.

Post by AlexMik » Sat 26 Jan 2008 16:53

Hi all,
Can anyone help me out with the following problem.
I create the following Form elements (TDBGridEh, TMyDataSource, TMyQuery) in the RunTime mode.
Then, using Query, I fill in created tables. One column in each table gets populated using PickList. Here is the actual problem. How would I go about processing the Event, when the user picks any value from the DropDownBox for the table created in the RunTime mode?

Code: Select all

procedure TFRM_Work_Shedule.FormCreate(Sender: TObject);
var TableClass, SourceClass, QueryClass: TControlClass;
    Work_Shedule_Table, Work_Shedule_DataSource, Work_Shedule_Query, Doctors_Query: TControl;
    i, j, table_width, table_coordinate, cabs_number: Integer;
    selecting_SQL, create_table_SQL: String;
begin
...
        i:=0;
        table_coordinate:=0;
        TableClass:=TControlClass(TDBGridEh);
        SourceClass:=TControlClass(TMyDataSource);
        QueryClass:=TControlClass(TMyQuery);
        while i<cabs_number do
        begin
        for j:=1 to 2 do
        begin
           Work_Shedule_Table:=TableClass.Create(WorkShedule_Doctors_SBox);
           Work_Shedule_Table.Parent:=WorkShedule_Doctors_SBox;
           Work_Shedule_DataSource:=SourceClass.Create(WorkShedule_Doctors_SBox);
           Work_Shedule_Query:=QueryClass.Create(WorkShedule_Doctors_SBox);
           Doctors_Query:=QueryClass.Create(WorkShedule_Doctors_SBox);

           TMyDataSource(Work_Shedule_DataSource).DataSet:=TMyQuery(Work_Shedule_Query);
           TDBGridEh(Work_Shedule_Table).DataSource:=TMyDataSource(Work_Shedule_DataSource);

           TDBGridEh(Work_Shedule_Table).TitleLines:=2;
           TDBGridEh(Work_Shedule_Table).Flat:=true;
           TDBGridEh(Work_Shedule_Table).Height:=WorkShedule_Doctors_SBox.Height;
           TDBGridEh(Work_Shedule_Table).Width:=150;
           table_width:=TDBGridEh(Work_Shedule_Table).Width;
           TDBGridEh(Work_Shedule_Table).Left:=table_coordinate;
           TDBGridEh(Work_Shedule_Table).AutoFitColWidths:=true;


           TMyQuery(Doctors_Query).Connection:=Data_Module.RBase_Connection;
           TMyQuery(Doctors_Query).SQL.Clear;
           TMyQuery(Doctors_Query).SQL.Add('SELECT * FROM doctorsref');
           TMyQuery(Doctors_Query).Execute;
           TDBGridEh(Work_Shedule_Table).Columns.Add.FieldName:='work_time';
           TDBGridEh(Work_Shedule_Table).Columns.Add.FieldName:='doctor_name';
           while not TMyQuery(Doctors_Query).Eof do
           begin
              TDBGridEh(Work_Shedule_Table).Columns.Items[1].PickList.Add(TMyQuery(Doctors_Query).FieldByName('doc_lname').AsString);
              TMyQuery(Doctors_Query).Next;
           end;
... ^^^^^^^^^^^^^^^^^^^^^^^^^^^'doctor_name' column Event
end; 
Thanks in advance for any help

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 29 Jan 2008 15:07

In order to process such event you can try to handle the TField.OnChange event. For that perform the next steps.
Create an event handler, for example:

Code: Select all

procedure TFRM_Work_Shedule.OnFieldChange(Sender: TField);
begin
  ShowMessage(Sender.AsString);
end;
Set this event handler for required field:

Code: Select all

  TMyQuery(Work_Shedule_Query).FieldByName('doctor_name').OnChange := OnFieldChange;

AlexMik
Posts: 6
Joined: Wed 26 Dec 2007 19:23

Post by AlexMik » Tue 29 Jan 2008 20:35

Yeah, tried that. Also tried using event UpdateData and the final result is the same. The problem is that when I choose any value from the list (DropDownBox), the event gets processed only after the current cell’s selection is lost. But what I need is the event triggered at the same time the value from the list gets selected.

Image

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 30 Jan 2008 13:31

This question is out of the MyDAC support scopes. Please ask it in the corresponding forum of the EhLib site.

Post Reply