• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 344
  • Last Modified:

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

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
johan777
Asked:
johan777
2 Solutions
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
geobulCommented:
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
 
johan777Author Commented:
Hi all, sorry for only getting back to you now.

I will split the points.

Thanx,
Js
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now