Recent

Author Topic: [Solved]Lazarus ProgrssBar throws error  (Read 7665 times)

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: Lazarus ProgrssBar throws error
« Reply #15 on: April 10, 2016, 12:56:42 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.timer(moneymachine: Integer);
  2. ...
  3. case moneymachine of  //Set Variables for the moneymachine
  4.       1:
  5.       begin
  6.         ProgressBar:=ProgressBar1;
  7.         lbltime:=lbltime1;
  8.       end;
  9.   end;  
moneymachine param is not 1 in first call, therefore the ProgressBar variable is NOT initialized (assigned), and that results in an AV further in code where you use it.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1263
Re: Lazarus ProgrssBar throws error
« Reply #16 on: April 10, 2016, 12:57:36 pm »
Code: [Select]
  case moneymachine of  //Set Variables for the moneymachine
      1:
      begin
        ProgressBar:=ProgressBar1;
        lbltime:=lbltime1;
      end;
  end;

The code can step through this case without ProgressBar being defined.  If it's not defined, then the AV you describe will occur.

Two choices:

Code: [Select]
  case moneymachine of  //Set Variables for the moneymachine
      1:
      begin
        ProgressBar:=ProgressBar1;
        lbltime:=lbltime1;
      end;
      else
         Progressbar:=Progressbar2;  // or something!
  end;

Or

Code: [Select]
...
  If Progressbar<>Nil Then
      ProgressBar.Position:=ProgressBar.Min;

In all honesty, both should be performed.
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Littellittel

  • New member
  • *
  • Posts: 8
Re: Lazarus ProgrssBar throws error
« Reply #17 on: April 10, 2016, 01:09:38 pm »
OMG that should have been obvious :D. ok many thanks to all of you i will keep an eye on that next time and creat a fallback method ;).

Is there anyway to accept an answere or something?

Many thanks again

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1263
Re: Lazarus ProgrssBar throws error
« Reply #18 on: April 10, 2016, 01:15:55 pm »
:-)  Glad we can help.

Quote
Is there anyway to accept an answere or something?

The generally accepted way is to edit the very first post and insert a "SOLVED" in the header.

The whole post can be also be locked (from the main Forum area), this is not usually done.

UPDATE:  @ncs-sniper: How do you identify your embedded your code as pascal code?  guessing this is a new feature since I've been away, looks useful...
« Last Edit: April 10, 2016, 01:28:03 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: [Solved]Lazarus ProgrssBar throws error
« Reply #19 on: April 10, 2016, 01:38:10 pm »
Code: [Select]
[code=pascal]...

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1263
Re: [Solved]Lazarus ProgrssBar throws error
« Reply #20 on: April 10, 2016, 01:39:31 pm »
That easy!   Many thanks :-)

Mike
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

 

TinyPortal © 2005-2018