Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
SetLength fall
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
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
const declaration
by
Zvoni
[
Today
at 08:05:29 am]
Troubles when converting ...
by
Zvoni
[
Today
at 08:02:11 am]
Batch "publish" of all pr...
by
dbannon
[
Today
at 07:59:53 am]
how to find application r...
by
Packs
[
Today
at 06:51:05 am]
H2Pas can't handle EXP CA...
by
Thaddy
[
Today
at 06:09:54 am]
Nested declarations insid...
by
Thaddy
[
Today
at 06:00:28 am]
File operations blocking ...
by
atlatl
[
Today
at 01:12:50 am]
Hustle - A simple task ma...
by
Wesbat
[
Today
at 12:24:34 am]
FP crashes after running ...
by
Martin_fr
[
Today
at 12:15:57 am]
VGM Player
by
Gigatron2
[
Today
at 12:03:16 am]
TImage colors incorrect
by
Jonny
[January 14, 2025, 11:27:29 pm]
SDL2 image rotation Probl...
by
Fred vS
[January 14, 2025, 11:18:08 pm]
[SOLVED]Might have a menu...
by
Tony Stone
[January 14, 2025, 10:39:56 pm]
/lib/x86_64-linux-gnu/lib...
by
DonAlfredo
[January 14, 2025, 09:00:28 pm]
SDL2: Runtime Error 216 o...
by
mischi
[January 14, 2025, 08:05:51 pm]
Iterator on non-existing ...
by
TRon
[January 14, 2025, 07:55:00 pm]
Out of memory / filter tw...
by
Thaddy
[January 14, 2025, 07:23:20 pm]
test if web site is valid
by
Thaddy
[January 14, 2025, 06:51:18 pm]
Quantize a PNG with TBgra...
by
circular
[January 14, 2025, 05:54:45 pm]
[SOLVED] Highlight commen...
by
artem101
[January 14, 2025, 05:19:04 pm]
Lazarus Release 3.6
by
Fred vS
[January 14, 2025, 03:23:01 pm]
CADSys4 3D.
by
mdadali
[January 14, 2025, 02:53:57 pm]
Color Buttons
by
lainz
[January 14, 2025, 01:04:56 pm]
Repository mirror and Ind...
by
Marc
[January 14, 2025, 12:27:48 pm]
Fpc Updates
by
loaded
[January 14, 2025, 12:19:36 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: SetLength fall (Read 610 times)
LemonParty
Jr. Member
Posts: 98
SetLength fall
«
on:
December 04, 2024, 02:58:34 pm »
Can anyone explain why next program falling at line
SetLength(B, 10000);
?
Logged
Fibonacci
Hero Member
Posts: 643
Internal Error Hunter
Re: SetLength fall
«
Reply #1 on:
December 04, 2024, 03:05:29 pm »
Its failing at this line:
Code: Pascal
[Select]
[+]
[-]
procedure
Go
;
var
Buf
:
TMnistImg
;
i
,
j
,
k
:
Integer
;
begin
SetLength
(
A
,
60000
)
;
for
k
:
=
1
to
60000
do
begin
for
i
:
=
1
to
28
do
for
j
:
=
1
to
28
do
begin
if
IsNan
(
Buf
[
j
,
i
]
)
then
A
[
k
]
[
i
,
j
]
:
=
0.0
else
A
[
k
]
[
i
,
j
]
:
=
Buf
[
j
,
i
]
/
255
;
end
;
end
;
SetLength
(
B
,
10000
)
;
end
;
Fix:
Code: Pascal
[Select]
[+]
[-]
for
k
:
=
0
to
high
(
A
)
do
begin
Logged
marcov
Administrator
Hero Member
Posts: 11980
FPC developer.
Re: SetLength fall
«
Reply #2 on:
December 04, 2024, 03:08:59 pm »
Probably it is accessing A[60000] just before that line. Debugger sometimes stop on the line after the problem.
Setlength(N) creates elements from 0 to N-1 not 1 to N
Logged
LemonParty
Jr. Member
Posts: 98
Re: SetLength fall
«
Reply #3 on:
December 04, 2024, 03:29:35 pm »
Thank you. I had to watch carefully. I knew about 0-base arrays.
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
SetLength fall
TinyPortal
© 2005-2018