#1 2024-08-05 08:20:03

youssef
Member
Registered: 2024-08-05
Posts: 2

Question About Passing TOrmClass in Service Function Causing Access Vi

How can I create a function in a service that contains a parameter var aClass: TOrmClass and use it in a test unit? When I try to implement this, I encounter an access violation error. Could you please advise on the correct approach or what might be causing the issue?
function

Offline

#2 2024-08-05 08:41:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,506
Website

Re: Question About Passing TOrmClass in Service Function Causing Access Vi

My guess is that it is not an access violation, but an exception.
The framework should in fact refuse to work with such kind of parameters.
Class parameters are not compatible with services.

A class parameter is in fact a pointer to the RTTI in the current executable.
There is no possibility to let it work in a client/server approach.

You can use a string with the class name instead, or even better an enumeration with a constant array to the actual TOrmClass.

Offline

#3 2024-08-05 09:01:36

youssef
Member
Registered: 2024-08-05
Posts: 2

Re: Question About Passing TOrmClass in Service Function Causing Access Vi

So, every time in the implementation, I need to do a case statement for each class like this:

case ClassType of
  User: DoSomething;
  Product: DoSomethingElse;
  ...
  ClassNumber15: DoAnotherThing;
  ...
end;
Is there a way to check which class is in the parameter and process it directly without having to check all cases one by one?

Last edited by youssef (2024-08-05 09:02:26)

Offline

#4 2024-08-05 09:35:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,506
Website

Re: Question About Passing TOrmClass in Service Function Causing Access Vi

You can use an array of const of the enumeration, pointing to TOrmClass, if you need to retrieve the local TOrmClass value, e.g. call a virtual method.

But if you need to just execute something depending on the class, a case statement for each class is the easiest.

Offline

Board footer

Powered by FluxBB