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
[Solved] A Tip for beginn...
by
silvercoder70
[
Today
at 10:15:43 pm]
Minor Q: HowTo use 'Debug...
by
PascalDragon
[
Today
at 10:06:58 pm]
Unit's name collides with...
by
TCH
[
Today
at 09:04:50 pm]
Select cell in listview
by
dsiders
[
Today
at 08:42:03 pm]
D2Bridge Framework for La...
by
nummer8
[
Today
at 08:20:59 pm]
UK's Online Safety Act
by
Thaddy
[
Today
at 07:54:31 pm]
using TForm.OnPaint to re...
by
robert rozee
[
Today
at 06:14:18 pm]
Drawing difference betwee...
by
Jonny
[
Today
at 05:05:54 pm]
Random ?
by
Thaddy
[
Today
at 04:43:11 pm]
Memory Safety and Object ...
by
Thaddy
[
Today
at 04:19:13 pm]
Spaces are allowed here ?
by
Thaddy
[
Today
at 04:06:29 pm]
Error 403 downloading wit...
by
Thaddy
[
Today
at 03:09:31 pm]
API on intranet - auth im...
by
MarkMLl
[
Today
at 02:17:27 pm]
Making sense of pparser, ...
by
Thaddy
[
Today
at 01:09:44 pm]
مشكلة في التقارير
by
nouzi
[
Today
at 12:47:27 pm]
Artificial intelligence
by
MarkMLl
[
Today
at 12:31:46 pm]
[SOLVED] Treeview flicker...
by
d7_2_laz
[
Today
at 12:13:44 pm]
No access to the wiki
by
dseligo
[
Today
at 12:01:01 pm]
SQL update statement and ...
by
Zvoni
[
Today
at 11:03:07 am]
Preparing FPC 3.2.4, poin...
by
AlexTP
[
Today
at 09:25:09 am]
IContainers
by
cdbc
[
Today
at 08:36:34 am]
Using Tesseract without i...
by
Thaddy
[
Today
at 07:41:06 am]
GR32 GR_Bindings problem
by
staratel20
[
Today
at 12:50:04 am]
(Solved) built IDE for qt...
by
HotShoe
[
Today
at 12:37:22 am]
Nested declarations insid...
by
Joanna from IRC
[
Today
at 12:29:42 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: SetLength fall (Read 640 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: 647
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: 11990
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