Jump to content
Stuart Clennett

Access Violation with a TFDMemTable placed on a datamodule inheriting from TMARSFDDataModuleResource

Recommended Posts



I got FireDAC functionality working with the EMPLOYEE table.   I wanted to load/save data using a json file for simple app config data, but as soon as I placed a TFDMemTable on the data module, I get an Access Violation when I request anything from that resource.  (E.g. a GET on the original Employee table).


The call stack says the a/v occurs in MARS.Data.FireDAC.TMARSFireDAC.InjectMacroValues(nil, True) which is in turn called from TMARSFDDataModuleResource.Retrieve.


I have not changed any properties on the FDMemTable nor added any code.  When I delete the component and recompile the server, the a/v goes away.


This can be easily replicated using the FireDACBasic demo, by adding a TFDMemTable to the Server.MainData datamodule.


Thanks for your help




Edited by Stuart Clennett

Share this post

Link to post

Hi @Stuart Clennett,

it's a bug! 🙂 Thanks for spotting it.

The TMARSFireDAC.InjectMacroValues and TMARSFireDAC.InjectParamValues implementations assume every TFDAdaptedDataSet actually has a Command (not nil). TFDMemTable do not have Command assigned.


Workaround: if you do not need your memory table to be included as the result of Retrieve method, you can decorate it with the RESTExclude attribute:


    FDMemTable1: TFDMemTable;


However, I just fixed this in the "develop" branch of MARS repository: https://github.com/andrea-magni/MARS/commit/b6299926671b00e75981c47a74375d9c51c529ca

Another workaround would be to change your copy of TMARSFDDataModuleResource.Retrieve and change this line:

    if LDataSet is TFDAdaptedDataSet then

to this:

    if (LDataSet is TFDAdaptedDataSet) and Assigned(TFDAdaptedDataSet(LDataset).Command) then


The MARS.Data.FireDAC.DataModule has nothing special, it is provided as an example of use, you can copy it, change it... it is obviously the counter-part of a TMARSFDResource but there no direct deal with the specific class, just matter of the shape of its methods (types returned, GET/POST selection, ...).




  • Like 1

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now