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
silvestre
[
Today
at 08:24:32 pm]
SDL2: Runtime Error 216 o...
by
mischi
[
Today
at 08:05:51 pm]
Iterator on non-existing ...
by
TRon
[
Today
at 07:55:00 pm]
how to find application r...
by
bytebites
[
Today
at 07:49:23 pm]
TImage colors incorrect
by
wp
[
Today
at 07:43:27 pm]
Nested declarations insid...
by
Warfley
[
Today
at 07:38:44 pm]
Out of memory / filter tw...
by
Thaddy
[
Today
at 07:23:20 pm]
/lib/x86_64-linux-gnu/lib...
by
WayneSherman
[
Today
at 07:21:26 pm]
test if web site is valid
by
Thaddy
[
Today
at 06:51:18 pm]
Troubles when converting ...
by
Thaddy
[
Today
at 06:12:36 pm]
Quantize a PNG with TBgra...
by
circular
[
Today
at 05:54:45 pm]
[SOLVED] Highlight commen...
by
artem101
[
Today
at 05:19:04 pm]
Lazarus Release 3.6
by
Fred vS
[
Today
at 03:23:01 pm]
CADSys4 3D.
by
mdadali
[
Today
at 02:53:57 pm]
Color Buttons
by
lainz
[
Today
at 01:04:56 pm]
Repository mirror and Ind...
by
Marc
[
Today
at 12:27:48 pm]
Fpc Updates
by
loaded
[
Today
at 12:19:36 pm]
file Blockread error
by
Thaddy
[
Today
at 11:53:53 am]
how to create sync applic...
by
Packs
[
Today
at 11:11:36 am]
SDL2 image rotation Probl...
by
Pe3s
[
Today
at 10:19:23 am]
How to combine data from ...
by
Zvoni
[
Today
at 10:17:05 am]
[SOLVED]Might have a menu...
by
dbannon
[
Today
at 09:07:11 am]
Why with allows assignmen...
by
egsuh
[
Today
at 06:46:30 am]
File operations blocking ...
by
TRon
[
Today
at 01:15:30 am]
[Solved] TPopupMenu OnDra...
by
d7_2_laz
[
Today
at 12:37:26 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: SetLength fall (Read 603 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