AL icon indicating copy to clipboard operation
AL copied to clipboard

ClientType causes Null Reference Exception

Open MarkusWinBI opened this issue 6 years ago • 6 comments

Describe the bug Using the ClientType for making client-specific modification causes a null reference exception System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

To Reproduce Steps and to reproduce the behavior: case ClientType of ClientType::Phone: IsPhoneClient := true; else IsPhoneClient := false; end;

Expected behavior Using ClientType is not causing a NullReference Exception

5. Versions:

  • AL Language: 3.0.150570
  • Business Central: 14.0.42627.0

MarkusWinBI avatar Jul 08 '20 08:07 MarkusWinBI

You need to check case CurrentClientType. The symbol ClientType is just the option type, containing available values, not an instance with a current value that can be checked.

Sure, it should say this instead of crashing the compiler, but it's still invalid code either way.

dzzzb avatar Jul 08 '20 09:07 dzzzb

You need to check case CurrentClientType. The symbol ClientType is just the option type, containing available values, not an instance with a current value that can be checked.

Sure, it should say this instead of crashing the compiler, but it's still invalid code either way.

Then can you give advice how to use the client Type option?

MarkusWinBI avatar Jul 08 '20 09:07 MarkusWinBI

I just said how, and it's documented.

case CurrentClientType of
  ClientType::Phone:
    IsPhoneClient := true;

  else
    IsPhoneClient := false;
end;

simplified:

IsPhoneClient := CurrentClientType = ClientType::Phone;

dzzzb avatar Jul 08 '20 09:07 dzzzb

As Phone client is just showing the first nonsense fields of a list I want to make fields invisible the customer has no use of in his use case (like the status

I just said how.

case CurrentClientType of
  ClientType::Phone:
    IsPhoneClient := true;

  else
    IsPhoneClient := false;
end;

simplified:

IsPhoneClient := CurrentClientType = ClientType::Phone;

Ooooooh! Just tooo simple! :-) Thanks very much!

MarkusWinBI avatar Jul 08 '20 09:07 MarkusWinBI

The Phoneclient is just ignoring it. It's not interested in "Visible = false", it's always showing the first five columns of the page, no matter if they are visible or not. But that's something different.

MarkusWinBI avatar Jul 08 '20 09:07 MarkusWinBI

Ugh, that sounds unfortunate. I'm glad to help with the easy bit but know nothing about that ;-)

dzzzb avatar Jul 08 '20 09:07 dzzzb