Solved

How can I force all data-aware controls to refresh from within TADOTable?

Posted on 2004-10-21
315 Views
Last Modified: 2010-04-05
Hi all,

I am populating some values in the AfterInsert event of a TADOTable component, but some of my data-aware controls does not refresh to show these changes. I am doing a DisableControls and EnableControls before and after the changes.

How do I go about to force the data-aware controls to refresh their contents (remember that I now have a TADOTable control in insert mode, for which some fields values have been prepopulated) WITHOUT KNOWING THE NAME(S) OF ALL THE CONTROLS.

This needs to be dynamic as I do not know which controls are attached to the TADOTable (via a TDataSource).

Regards,
Johan Swart
0
Question by:johan777
    3 Comments
     
    LVL 22

    Accepted Solution

    by:
    Try with this:

    Add typinfo to the uses.

    In your afterinsert add this part....

    var
      i     :  Integer;
      CNTRL :  TControl;
      p     :  PPropInfo;
    begin
      [...]
      //EnableControls;
      for i:=0 to ComponentCount-1 do
      begin
        if ((Components[i] is TControl)) then
        begin
          CNTRL := TControl(Components[i]);
          p := GetPropInfo(CNTRL.ClassInfo, 'DataSource'); //Is cntrl data-aware
          if (p <> nil) then
          begin
            if  TDataSource(GetOrdProp(CNTRL, p)) <> nil then //you could test if it's = yourDataSouce instead
             CNTRL.Refresh; //let's refresh the data-aware control
          end;
    end;

    Just from head

    F68 ;-)
    0
     
    LVL 17

    Assisted Solution

    by:geobul
    Hi,

    EnableControls should do that (it works OK here, at least). But it could be possible that not every call of DisableControls has one EnableControls call. For that reason there is the following example in Delphi help:

    procedure ReEnableControls (DataSet: TDataSet);
    begin
    while DataSet.ControlsDisabled do
      DataSet.EnableControls;
    end;

    Hope it will help you. Just call that procedure as a last line in Table.AfterPost event, for instance.

    The following is a simple example of doing what you need (without using the procedure above). I'm able to see the value of Account_ID field ('6' in this case) in DBEdit1 after pressing btnInsert:

    TForm1 = class(TForm)
        ADOConnection1: TADOConnection;
        ADOTable1: TADOTable;
        DataSource1: TDataSource;
        DBEdit1: TDBEdit;
        DBEdit2: TDBEdit;
        btnInsert: TButton;
        btnPost: TButton;
        procedure btnInsertClick(Sender: TObject);
        procedure ADOTable1AfterInsert(DataSet: TDataSet);
        procedure btnPostClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.DFM}

    procedure TForm1.btnInsertClick(Sender: TObject);
    begin
      ADOTable1.Insert;
    end;

    procedure TForm1.ADOTable1AfterInsert(DataSet: TDataSet);
    begin
      ADOTable1.DisableControls;
      ADOTable1.FieldByName('Account_ID').AsString := '6';
      ADOTable1.EnableControls;
    end;

    procedure TForm1.btnPostClick(Sender: TObject);
    begin
      ADOTable1.Post;
    end;

    Regards, Geo
    0
     

    Author Comment

    by:johan777
    Hi all, sorry for only getting back to you now.

    I will split the points.

    Thanx,
    Js
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Learn The Basics of Ethical Hacking & Pen Testing

    Computer and network security is one of the fastest growing and most essential industries in technology, meaning companies will pay big bucks for ethical hackers. This is the perfect course to leap into this lucrative career, learning how to use ethical hacking to reveal ...

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now