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
TImage colors incorrect
by
Khrys
[
Today
at 07:15:03 am]
Any RequestOpenDirectory ...
by
Thaddy
[
Today
at 07:14:51 am]
Add additional Components...
by
cdbc
[
Today
at 07:03:25 am]
const declaration
by
Thaddy
[
Today
at 06:53:31 am]
H2Pas can't handle EXP CA...
by
TRon
[
Today
at 06:20:17 am]
Creating a SDL child wind...
by
TRon
[
Today
at 06:17:08 am]
String replace or add ' ...
by
Thaddy
[
Today
at 06:14:41 am]
File operations blocking ...
by
atlatl
[
Today
at 05:44:51 am]
Nested declarations insid...
by
440bx
[
Today
at 04:26:28 am]
[solved] triple click
by
dbannon
[
Today
at 01:46:22 am]
SDL2 image rotation Probl...
by
Fred vS
[
Today
at 01:13:15 am]
SetPart ?
by
BubikolRamios
[January 15, 2025, 11:32:19 pm]
TRichMemo High Lighted te...
by
What I can do
[January 15, 2025, 11:20:37 pm]
Lazarus/FPC Flatpak appli...
by
Chronos
[January 15, 2025, 09:56:54 pm]
The mouse and using ptcgr...
by
TBMan
[January 15, 2025, 09:15:40 pm]
SDL2: Runtime Error 216 o...
by
TRon
[January 15, 2025, 07:44:59 pm]
Iterator on non-existing ...
by
Warfley
[January 15, 2025, 05:45:03 pm]
Batch "publish" of all pr...
by
MarkMLl
[January 15, 2025, 05:42:45 pm]
[solved] Setting the init...
by
TBMan
[January 15, 2025, 04:28:08 pm]
MQTT Client
by
cdbc
[January 15, 2025, 03:06:25 pm]
Issue getting and setting...
by
d7_2_laz
[January 15, 2025, 02:28:48 pm]
Problem with cell comment
by
kjteng
[January 15, 2025, 02:17:57 pm]
[SOLVED]Troubles when con...
by
bytebites
[January 15, 2025, 01:15:16 pm]
FP crashes after running ...
by
marcov
[January 15, 2025, 10:06:01 am]
Repository mirror and Ind...
by
Thaddy
[January 15, 2025, 10:02:53 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: SetLength fall (Read 622 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: 11982
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