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
File operations blocking ...
by
TRon
[
Today
at 01:15:30 am]
test if web site is valid
by
dbannon
[
Today
at 01:08:05 am]
[Solved] TPopupMenu OnDra...
by
d7_2_laz
[
Today
at 12:37:26 am]
how to make application r...
by
DragoRosso
[
Today
at 12:19:23 am]
Discussion: How do you di...
by
dbannon
[
Today
at 12:18:30 am]
Lazarus Release 3.6
by
c600g
[
Today
at 12:01:39 am]
Nested declarations insid...
by
Warfley
[January 13, 2025, 10:46:05 pm]
Assigning proc to event a...
by
Bart
[January 13, 2025, 10:16:59 pm]
SDL2 image rotation Probl...
by
TRon
[January 13, 2025, 10:00:09 pm]
Why with allows assignmen...
by
PascalDragon
[January 13, 2025, 09:53:19 pm]
how to create sync applic...
by
Thaddy
[January 13, 2025, 09:22:14 pm]
Color Buttons
by
lainz
[January 13, 2025, 09:14:49 pm]
Lazarus Pascal Keywords a...
by
PascalDragon
[January 13, 2025, 09:11:42 pm]
Generics as PUBLISHED imp...
by
PascalDragon
[January 13, 2025, 09:04:43 pm]
FP crashes after running ...
by
Martin_fr
[January 13, 2025, 09:03:42 pm]
Random ?
by
Thaddy
[January 13, 2025, 07:26:20 pm]
UnoLib - library in Pasca...
by
ackarwow
[January 13, 2025, 07:08:06 pm]
file Blockread error
by
TBMan
[January 13, 2025, 07:02:54 pm]
¿Hay alguna limitación en...
by
e_nigma
[January 13, 2025, 06:27:03 pm]
Exploring FPC/Lazarus uni...
by
MarkMLl
[January 13, 2025, 05:48:05 pm]
Web Pascal without JavaSc...
by
zendrael
[January 13, 2025, 05:19:57 pm]
MainMenu: How to use the ...
by
madref
[January 13, 2025, 03:03:37 pm]
How to combine data from ...
by
Thaddy
[January 13, 2025, 02:30:11 pm]
SDL2: Runtime Error 216 o...
by
mischi
[January 13, 2025, 02:11:35 pm]
Might have a menu bug in ...
by
cdbc
[January 13, 2025, 01:46:12 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: SetLength fall (Read 597 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