After upgrading 2.4.5.4 Twebclientdataset can be reloaded

Hi,

After upgrading to TMSWeb Core 2.4.5.4, when you tried to reload a clientdataset previously opened on the form, it doesnt reopen.

Firefox 122.0.1 (64-bit)
Delphi 11.3
TMS web Core 2.4.5.4

Steps to recreate problem:

  1. Add a TWebClientdataset and TWebClientConnection
  2. Add a webbutton1 and Configure as usual connection to TWebClientConnection and TWebClientdataset by code:

WbcAP.Active := false;
WcdAP.Active := false;

WbcAP.URI := 'URL'
WbcAP.Command := httpPOST;

WbcAP.Headers.clear;
WbcAP.Headers.Add('X-HEADERS');
WbcAP.Active := true;
WcdAP.Active := true;

  1. Put an Afteropen event on the clientdataset with this example code:

WcdAP.First;

while not WcdAP.Eof do
begin
console.log('cantidad registro'+WcdAP.RecNo.ToString + '/' + WcdAP.RecordCount.ToString );

      WcdAP.Next;
  end;
  1. Compile and run. If you press the webbutton1 the first time you will see in the console that the code run with the recno/recound count for each record on the console.

If you press the webbutton1 again, the afteropen code wont just do anything. The strange part is that there is no error message in the console , it just doesnt reload the clientdataset for some reason.

Tested with current project, an old unmodified project, and new project and the problem is the same.

I retested this with demo Demo\Basics\DBGrid and add a button with code:

begin
  webclientconnection1.Active := false;
  webclientconnection1.Active := true;
end;

and it reopens the dataset.

Other than this, we did not really make changes in TWebClientDataSet between v2.4.5.3 and 2.4.5.4.

The only change we did was in WEBLib.CDS.pas change

procedure TClientConnection.DoDisconnect;
begin
  if Assigned(FDS) then
  begin
     if FAutoOpen then
     begin
       FDS.Active := false;
       FDS.FieldDefs.Clear;
     end;
  end;
end;

to

procedure TClientConnection.DoDisconnect;
begin
  if Assigned(FDS) then
  begin
     if FAutoOpen then
     begin
       FDS.Active := false;
       FDS.Fields.Clear;
     end;
  end;
end;

but I cannot see this having any effect on what you do.

Hi Bruno,

Please try recreating the steps provided using the afteropen event on the webclientdataset and using button code provided, and you will be able to recreate the problem.

After doing a network inspect the webconnection is working well, it gets the data with the POST when you request the data again.

The problem is with the client dataset updating after the webconection reload. After reloading the data from the webconnection to the webclientdataset the recordcount is 0 on the webclientdataset.

Please isolate this and provide a test app with source code we can debug here.
Compare also with our demo where no issue can be seen.

Trying to replicate something based on just a code snippet (where for example I need to guess the type of WcdAP) is error prone and inefficient.

Hi Bruno,

Upgraded to 2.4.6 and tested the problem with the Demo\Basics\DBGrid

Added a new webbutton1 with the following code:

Added a button with the following code:

WebClientConnection1.Active := false;
WebClientDataSet1.active := false;

WebClientConnection1.Active := true;
WebClientDataSet1.active := true;

Then compiled and run the application, when pressing the button1 it doesnt refresh the data of the clientdataset neither grid

Noticed the problem. If specific with the clientdataset activating code:

for example
WebClientConnection1.Active := false;
WebClientDataSet1.active := false;

WebClientConnection1.Active := true;
WebClientDataSet1.active := true; <- the error comes from this line of code.

This error wasnt present on previous version of TMS web core noticed after upgrading to 2.4.5.4 and 2.4.6

Hi Bruno,

Think you didnt see the last post about using the tms demo dbgrid code.

Attach a example project showcasing the error using the DEMO/Basic/dbgrid project

Previous post:
DBGrid.zip (2.4 MB)

Hi Bruno,

Upgraded to 2.4.6 and tested the problem with the Demo\Basics\DBGrid

Added a new webbutton1 with the following code:

Added a button with the following code:

WebClientConnection1.Active := false;
WebClientDataSet1.active := false;

WebClientConnection1.Active := true;
WebClientDataSet1.active := true;

Then compiled and run the application, when pressing the button1 it doesnt refresh the data of the clientdataset neither grid

Noticed the problem. If specific with the clientdataset activating code:

for example
WebClientConnection1.Active := false;
WebClientDataSet1.active := false;

WebClientConnection1.Active := true;
WebClientDataSet1.active := true; <- the error comes from this line of code.

This error wasnt present on previous version of TMS web core noticed after upgrading to 2.4.5.4 and 2.4.6

Setting WebClientConnection.Active = true causes the WebClientDataSet to be asynchronously updated (loading JSON is asynchronous in web!). You cannot assume the data to be available in the next line where you set WebClientDataSet.Active = true.
That is why WebClientConnection has the property AutoOpenDataSet so it will asynchronously open the dataset when the data was loaded.
So, either use this or set WebClientDataSet.Active from WebClientConnection.AfterConnect

Hi Bruno,

I comprehend and concur with what you say. However, I'm curious as to why this issue didn't arise in the previous version, and why it's become problematic since 2.4.5.4?

Changing this particular section of the code in a substantial project is bound to be a time-intensive endeavor. Essentially, it entails scrutinizing numerous forms that have remained unmodified for an extended period. The expectation is that upgrading a component should not lead to such repercussions, especially when dealing with a component as fundamental as the client dataset behavior pattern.

You're correct this should not cause repercussions.
This issue didn't surface in our tests and after all, human errors can happen and humans are ready to repair these quickly.

No problem at all! im a happy webcore user and recommend a lot the use of Web core to my fellows delphi programmers.

Can i expect a solution to this case or would have to modify extensively our current project?

in other cases wont be too much of a problem for us, but right now we are needing to make a lot of changes to our application and this is making that we have to stop any new development and concentrate in change all this form and retesting basically the whole webapp.

We look to bring a solution.