Board index » delphi » Assignment statement resets computer? (Delphi 1)

Assignment statement resets computer? (Delphi 1)

I'm a beginner with Delphi.  I'm forced to use version 1 because I need to
create 16-bit executables.

As always when learning a new language, I'm fiddling around and creating "toy"
applications.  Today, I created a button with this handler:

procedure Update;

var
        Units : array[1..50] of string ;
        Index : integer;

begin
        for Index := 1 to Length.units.lines.count do
                Units[Index] := Length.units.lines[Index];

        messageDlg(Units[1],mtInformation,[mbOK],0);
end;

This code just counts through the lines of a memo object (on another page),
then assigns each of those lines to a member of the array "units".  Length is
a form, units is a memo object.

Yes, I know that there's no reason to actually do this.  As I said, I'm
fiddling around and learning the syntax.

If I compile this program, clicking that button causes a GPF.  If I hit F9
within the IDE, clicking it repeatably gives me a "black screen of death" on
my PC.  The video signal stops, it doesn't respond to any keystrokes, and I
have to power off to restart it.

I have no idea what's wrong with that statement.  There are fewer than 50
lines in the memo.

Any suggestions?

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

 

Re:Assignment statement resets computer? (Delphi 1)


Try
        for Index := 0 to Length.units.lines.count - 1 do

ca...@panix.com wrote in article <6ointt$3n...@nnrp1.dejanews.com>...

Quote
> I'm a beginner with Delphi.  I'm forced to use version 1 because I need
to
> create 16-bit executables.

> As always when learning a new language, I'm fiddling around and creating
"toy"
> applications.  Today, I created a button with this handler:

> procedure Update;

> var
>    Units : array[1..50] of string ;
>    Index : integer;

> begin
>    for Index := 1 to Length.units.lines.count do
>            Units[Index] := Length.units.lines[Index];

>    messageDlg(Units[1],mtInformation,[mbOK],0);
> end;

> This code just counts through the lines of a memo object (on another
page),
> then assigns each of those lines to a member of the array "units".
Length is
> a form, units is a memo object.

> Yes, I know that there's no reason to actually do this.  As I said, I'm
> fiddling around and learning the syntax.

> If I compile this program, clicking that button causes a GPF.  If I hit
F9
> within the IDE, clicking it repeatably gives me a "black screen of death"
on
> my PC.     The video signal stops, it doesn't respond to any keystrokes, and
I
> have to power off to restart it.

> I have no idea what's wrong with that statement.  There are fewer than 50
> lines in the memo.

> Any suggestions?

> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Re:Assignment statement resets computer? (Delphi 1)


Hi
All of the components that ship with Delphi3 (that I know of) use zero based
indexes for their indexed properties. I think your proc bombs when you try
to access Length.units.lines[index] when index = Length.units.lines.count.

Try this instead:

procedure Update;

var
Units : array[0..49] of string ;
Index : integer;

begin
for Index := 0 to Length.units.lines.count - 1 do
Units[Index] := Length.units.lines[Index];

messageDlg(Units[0],mtInformation,[mbOK],0);
end;

It should work in Delphi 1.
Good luck
__________________________________
Chris Olivier
coliv...@netcons.MAPSON.co.za  << Remove NOSPAM

Network & Computing Consultants
Bloemfontein
South Africa
__________________________________

Quote
ca...@panix.com wrote in message <6ointt$3n...@nnrp1.dejanews.com>...
>I'm a beginner with Delphi.  I'm forced to use version 1 because I need to
>create 16-bit executables.

>As always when learning a new language, I'm fiddling around and creating
"toy"
>applications.  Today, I created a button with this handler:

>procedure Update;

>var
> Units : array[1..50] of string ;
> Index : integer;

>begin
> for Index := 1 to Length.units.lines.count do
> Units[Index] := Length.units.lines[Index];

> messageDlg(Units[1],mtInformation,[mbOK],0);
>end;

SNIP

Re:Assignment statement resets computer? (Delphi 1)


Quote
In article <6ointt$3n...@nnrp1.dejanews.com>, ca...@panix.com writes:
>I'm a beginner with Delphi.  I'm forced to use version 1 because I need to
>create 16-bit executables.

>As always when learning a new language, I'm fiddling around and creating
>"toy"
>applications.  Today, I created a button with this handler:

>procedure Update;

>var
>    Units : array[1..50] of string ;
>    Index : integer;

>begin
>    for Index := 1 to Length.units.lines.count do
>            Units[Index] := Length.units.lines[Index];

>    messageDlg(Units[1],mtInformation,[mbOK],0);
>end;

In Delphi (and as is usual in computers) most indices start with zero so you
have Count lines in your TMemo with indices from 0 to Count - 1. Change to :-
  for Index := 0 to Length.units.lines.count - 1 do.

Then you would have to alter your next line to :-
  Units[Index + 1] := . . .

It's most likely easier to have indices in general starting with 0, and if
there are over-riding reasons to start with another number, then comment well
<g>.

You were treading over someone elses memory <g>

Alan Lloyd
alangll...@aol.com

Re:Assignment statement resets computer? (Delphi 1)


In article <6ok1sd$...@news1.saix.net>,
  "Chris Olivier" <coliv...@netcons.MAPSON.co.za> wrote:

Quote
> All of the components that ship with Delphi3 (that I know of) use zero based
> indexes for their indexed properties. I think your proc bombs when you try
> to access Length.units.lines[index] when index = Length.units.lines.count.

Thank you, and also thanks to Finn who pointed out my mistake as well.

Question:  even if I did something stupid like read past the end of a
TStrings object . . . should it really cause a completely frozen,
power-switch-to-restart situation? -- Carl Fink  ca...@dm.net Manager,
Dueling Modems Computer Forum http://www.dm.net/

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Other Threads