Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-21
3
Medium Priority
?
336 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
Comment
Question by:johan777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 750 total points
ID: 12368793
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
geobul earned 750 total points
ID: 12369128
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
ID: 12553046
Hi all, sorry for only getting back to you now.

I will split the points.

Thanx,
Js
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 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