Recent

Author Topic: [Win32] Crash... Any suggestions?  (Read 6203 times)

Reenen

  • New Member
  • *
  • Posts: 29
    • http://daringapprentice.wikispaces.com
[Win32] Crash... Any suggestions?
« on: April 26, 2005, 02:02:21 pm »
I do not know why my application crashes... Here is the error message:
(http://img.villagephotos.com/p/2005-3/983433/error.jpg)

It crashes when I click a certain menu-item.  I am not sure why it is.

It might be because I have subfunctions... ie:

Code: [Select]

Procedure TfrmMain.ImportData;
Type
  TRecord = Record
...
  end;

var
  vars : Array of TRecord;
 
  Function DoStuff;  //Sub Function
  begin
     vars[1]...
  end;

begin   // Main part of Importdata
  DoStuff;
end;


But it worked for a while, and now it doesn't.  I don't know what's happening, and I can't debug it for some reason.  Adding a breakpoint does nothing.

-Reenen

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
[Win32] Crash... Any suggestions?
« Reply #1 on: April 26, 2005, 02:24:56 pm »
With this little code I can't really tell, what is wrong with your code.

Usually, if you run code in the IDE with the debugger enabled, I will show you the location of the error.
I just tried an event handler for a menu item with a nested function and had no such error.

Reenen

  • New Member
  • *
  • Posts: 29
    • http://daringapprentice.wikispaces.com
[Win32] Crash... Any suggestions?
« Reply #2 on: April 26, 2005, 03:02:28 pm »
How does Lazarus implement dynamic Arrays?

Can I just do

Code: [Select]

var arr : array of integer;

begin
  arr[0] := 1;
  arr[1] := 4;
end;


Or will this give an error?

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
[Win32] Crash... Any suggestions?
« Reply #3 on: April 26, 2005, 03:11:08 pm »
This will give an access violation, because you didn't allocate memory for the array.

Revised example (untested)
Code: [Select]

var arr : array of integer;

begin
  SetLength(array, 2); // don't forget this.
  arr[0] := 1;
  arr[1] := 4;
end;


You don't need to free the array after using it, the compiler generates code for that.

Reenen

  • New Member
  • *
  • Posts: 29
    • http://daringapprentice.wikispaces.com
[Win32] Crash... Any suggestions?
« Reply #4 on: April 26, 2005, 05:07:54 pm »
Which unit should I use to get access to SetLength?

Reenen

  • New Member
  • *
  • Posts: 29
    • http://daringapprentice.wikispaces.com
[Win32] Crash... Any suggestions?
« Reply #5 on: April 26, 2005, 05:08:51 pm »
Oops... no, its working... I must've mistyped it the first time.

 

TinyPortal © 2005-2018