Home How in Object Pascal find whether a character is alphanumeric or underscore working in both Delphi compiler and FPC?
Reply: 1

How in Object Pascal find whether a character is alphanumeric or underscore working in both Delphi compiler and FPC?

Lukas Salich
1#
Lukas Salich Published in 2017-09-13 09:28:31Z

There are similar or same questions all over the internet, but the answers don't work for me. We develop multiplatform product, which is compiled both under Delphi's compiler and under FPC. First, I used:

Uses:
  System.Character;

and

Character.TCharacter.IsLetterOrDigit(..)

, but it couldn't be compiled under FPC, so according to some other source, I used:

Uses:
  Character;

and

TCharacter.IsLetterOrDigit(..)

instead, but still can't be compiled under FPC.

Can someone find a way that the code will work on both Delphi compiler and FPC? I don't have FPC set up to work with my project, so I can't figure out on my own, how to fix the code to work in FPC (I can test it only in complicated way via build server) and can't find a way, how to do it.

I also wanted to write it using regex, but colleagues say, that it would be too complicated for them.

David Heffernan
2#
David Heffernan Reply to 2017-09-13 09:47:07Z

Both Delphi and FPC include a class named TCharacter which exposes a method named IsLetterOrDigit. In other words, the premise of your question is wrong. It is perfectly reasonable to use TCharacter.IsLetterOrDigit.

Documentation links:

  • Delphi: http://docwiki.embarcadero.com/Libraries/en/System.Character.TCharacter
  • FPC: https://www.freepascal.org/docs-html/3.0.0/rtl/character/tcharacter.html

It's entirely possible that you are using an out of date version of FPC, which would explain why your code fails. Although that is guesswork since you did not include any details of the error message.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.323933 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO