Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Free Pascal
»
General
(Moderators:
FPK
,
Tomas Hajny
) »
[SOLVED] „Error: Constant and CASE types do not match‟ with string
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
made hooking newinstance ...
by
Handoko
[
Today
at 05:32:17 pm]
XLibre, finally and fortu...
by
Fred vS
[
Today
at 05:18:57 pm]
Pdf Viewer in Pascal
by
Tomxe
[
Today
at 05:00:32 pm]
[New Component] ExtTabCtr...
by
ovidio
[
Today
at 04:22:52 pm]
Sizes and SizeInt
by
LemonParty
[
Today
at 03:05:53 pm]
How can 'Canvas does not ...
by
J-G
[
Today
at 03:05:01 pm]
AArch64. Fast method to c...
by
Thaddy
[
Today
at 01:58:45 pm]
I found an actual use for...
by
Thaddy
[
Today
at 01:07:16 pm]
Strange Behaviour at Runt...
by
andrew Bubble
[
Today
at 12:41:49 pm]
water filling simulation
by
Dzandaa
[
Today
at 12:35:32 pm]
Can /my/ AI help me with ...
by
microxa
[
Today
at 12:12:06 pm]
Knigo
by
CM630
[
Today
at 12:05:31 pm]
P.I.S.S. a PlugIn-framewo...
by
cdbc
[
Today
at 11:27:35 am]
[solved] rotate image pro...
by
speter
[
Today
at 10:03:42 am]
Lazarus Main and Gnome/Wa...
by
zeljko
[
Today
at 09:06:57 am]
TstringGrid read cell col...
by
Josh
[June 08, 2026, 11:05:23 pm]
Pascal for AI Agent CLI T...
by
schuler
[June 08, 2026, 10:35:41 pm]
is there a Base 26 / Radi...
by
Josh
[June 08, 2026, 08:54:36 pm]
FPC Unleashed (inline var...
by
Fibonacci
[June 08, 2026, 08:49:31 pm]
Notetask 1.1.4 - Free cro...
by
AlexanderT
[June 08, 2026, 04:55:38 pm]
Pixie: A lightweight HTML...
by
Tomxe
[June 08, 2026, 01:48:30 pm]
EasyLazFreeType Bug?
by
Tommi
[June 08, 2026, 10:57:47 am]
embed .jpg file into .pp ...
by
Thaddy
[June 08, 2026, 09:51:38 am]
Call SetLength from assem...
by
Thaddy
[June 08, 2026, 09:00:36 am]
TPlaysound problem Ubuntu...
by
jamie
[June 08, 2026, 12:57:32 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] „Error: Constant and CASE types do not match‟ with string (Read 10835 times)
CM630
Hero Member
Posts: 1696
Не съм сигурен, че те разбирам.
[SOLVED] „Error: Constant and CASE types do not match‟ with string
«
on:
July 09, 2018, 03:31:48 pm »
Following code works right:
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
Button1Click
(
Sender
:
TObject
)
;
var
A
:
string
=
''
;
B
:
string
=
'B'
;
C
:
string
=
'C'
;
begin
A
:
=
B
;
case
A
of
'B'
:
ShowMessage
(
B
)
;
'C'
:
ShowMessage
(
C
)
;
end
;
end
;
But this code generates „Error: Constant and CASE types do not match‟.
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
Button1Click
(
Sender
:
TObject
)
;
var
A
:
string
=
''
;
B
:
string
=
'B'
;
C
:
string
=
'C'
;
begin
A
:
=
B
;
case
A
of
B
:
ShowMessage
(
B
)
;
C
:
ShowMessage
(
C
)
;
end
;
end
;
B and C are strings. I tryed to cast to cast them to strings, anyway, but still I get the same error?
Is it me doing sth. wrong?
«
Last Edit: July 09, 2018, 04:00:45 pm by CM630
»
Logged
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2
RayoGlauco
Full Member
Posts: 227
Beers: 1567
Re: „Error: Constant and CASE types do not match‟ with string
«
Reply #1 on:
July 09, 2018, 03:49:09 pm »
In the second example, you use variables as selectors, instead of constants (B is a variable; 'B' is a constant). You cannot use variables as selectors.
See
http://wiki.freepascal.org/Case
Logged
To err is human, but to really mess things up, you need a computer.
Thaddy
Hero Member
Posts: 19258
Glad to be alive.
Re: „Error: Constant and CASE types do not match‟ with string
«
Reply #2 on:
July 09, 2018, 03:50:04 pm »
Needs a literal value, indeed.
Logged
objects are fine constructs. You can even initialize them with constructors.
Gammatester
Jr. Member
Posts: 69
Re: „Error: Constant and CASE types do not match‟ with string
«
Reply #3 on:
July 09, 2018, 03:50:20 pm »
You should read the second part of the error message 'Error: String expression expected'. The case labels must be constants (i.e. literals or true constants). Your construct would throw equivalent message even for integer variables. The following code does work:
Code: Pascal
[Select]
[+]
[-]
var
A
:
string
=
''
;
const
B
=
'B'
;
C
=
'C'
;
begin
A
:
=
B
;
case
A
of
B
:
writeln
(
B
)
;
C
:
writeln
(
C
)
;
end
;
end
;
Logged
CM630
Hero Member
Posts: 1696
Не съм сигурен, че те разбирам.
Re: „Error: Constant and CASE types do not match‟ with string
«
Reply #4 on:
July 09, 2018, 03:57:15 pm »
Ok, thanks, I will rewrite it with
Quote
If... then.
Logged
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Free Pascal
»
General
(Moderators:
FPK
,
Tomas Hajny
) »
[SOLVED] „Error: Constant and CASE types do not match‟ with string
TinyPortal
© 2005-2018