Lazarus

Programming => General => Topic started by: Jake012345 on July 14, 2020, 10:26:26 pm

Title: Object Referrence is nil
Post by: Jake012345 on July 14, 2020, 10:26:26 pm
Hello!
I'm trying to make a BlackJack.
But now, on a test, I can't run it, because It's coming back with an error (Object referrence is nil)
Title: Re: Object Referrence is nil
Post by: winni on July 14, 2020, 10:38:23 pm
Hi!

My compiler says:

Code: Text  [Select][+][-]
  1. Messages, Errors: 4
  2. Error: File "Images\karo.bmp" not found.
  3. Error: File "Images\kor.bmp" not found.
  4. Error: File "Images\pikk.bmp" not found.
  5. Error: File "Images\treff.bmp" not found.
  6.  

So I can't test it.

Winni
Title: Re: Object Referrence is nil
Post by: Jake012345 on July 14, 2020, 11:10:41 pm
But theese are here!
I tried to move them back to project folder, but happens same.
Title: Re: Object Referrence is nil
Post by: winni on July 14, 2020, 11:22:42 pm
Hi!

Please look into the ZIP-file:

The bmp-files are NOT there!

Winni
Title: Re: Object Referrence is nil
Post by: Bart on July 14, 2020, 11:37:52 pm
B.t.w. Winni is right, no bitmaps in the zip.
I simply created 4 dummy bitmaps with the correct names in the correct subfolder.


Maybe this explains the runtime error?

Code: [Select]
Compile Project, Target: BlackJack.exe: Success, Warnings: 4, Hints: 1
...
bjmain.pas(38,3) Warning: Variable "icoPikk" read but nowhere assigned
bjmain.pas(38,12) Warning: Variable "icoKor" read but nowhere assigned
bjmain.pas(38,20) Warning: Variable "icoTreff" read but nowhere assigned
bjmain.pas(38,30) Warning: Variable "icoKaro" read but nowhere assigned

It is always a good idea to look carefully at the messages the compiler gives you.

You do icoPikk.LoadFromStream(iconRes, 1), but you did not create an instance of icoPikk, so this variable (since it is a global variable) is nil.

I resolved this by creating each variable as of type TBitmap (icoPikk := TBitmap.Create), but then got an error upon LoadFromStream:
Code: [Select]
FPImageException
Bitmap with unknown compression (5848020)

I finally simply replace the loading from resource with loading form file, so it works.

You can make life much easier IMO if you simply put these four images into a TImageList at design time.

Bart
Title: Re: Object Referrence is nil
Post by: Bart on July 14, 2020, 11:49:58 pm
Some other remarks:

Bart
Title: Re: Object Referrence is nil
Post by: Jake012345 on July 14, 2020, 11:56:55 pm
Thanks! that's working.

(I'm just tested that I can show the icons of the cards. Sure I'll add numbers and... make a game! ;) )
TinyPortal © 2005-2018