Calculated fields in TXDataWebDataSet - Is this possible?

Hello Wagner,

Part 1, simple question
I would like to use calculated fields in an XData DataSet in a WebCore Application.
How can I add fields manually?
The original fields (from the RESTServer) only exist when the data set is opened.

If possible, part 2
I have my own component that displays the data in a list on a pure (freely configurable) HTML basis.. But now I would like to work on the standard query with the built-in methods, but have additional fields in the dataset (would be much easier to program than if I had to do it manually).

If everything goes, then also part 3?
To make it even more complicated... ;-)
I have a web.plugin (see music demo) and there I can use different list views (TWebDBTableControl or my HtmlList component). I can change the display at will. Depending on the use case.

Unfortunately, the exclusive use of a Columns Collection does not work in conjunction with XData.

Do I have a problem or am I making it too complicated?

Best regards
Thomas

Hi Thomas,

You should add calculated fields manually to the Web Dataset, just like you would do in a regular dataset. Thus, you should create all data fields, and then also the calculated fields.

About part 2, I'm not sure if I understood your question, but if I did, then it should be as I said above: it's a dataset, and like any dataset in Delphi, if you want to bind any data to a control, there should be a field. To have a field, you have to create it in advance.

What do you mean by that, exactly?

Yes, tested for hours and didn't notice the error.
On the web, I still have trouble really noticing all the errors. Html and Javascript keep running and don't throw an exception. I have to add something there.

I had an error when creating the fields manually.
The statement NewField.Dataset := Dataset automatically adds the field. I had always tried to call the "Add" function. And did not notice this error. So everything else didn't work either because the website just stopped loading.

Now it seems to be working.

Is there a way to add a general exception handler so that every (native) Delphi exception is thrown?

    NewField := AFieldClass.Create( TheDataset);
    NewField.FieldKind := AFieldKind;
    NewField.FieldName := AFieldname;
    NewField.Calculated := (AFieldKind = TFieldKind.fkCalculated);
    NewField.Required := not NewField.Calculated;
    NewField.Size := ASize;
    NewField.DataSet := TheDataset;

The right code to add a field. Do not call an add function.

Always check the browser console. That's where you check for everything that is happening (including errors) in your web application.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.