Recent

Author Topic: Object Referrence is nil  (Read 267 times)

Jake012345

  • Sr. Member
  • ****
  • Posts: 253
  • 'The knowledge is the key.'
    • FPCProjectShare
Object Referrence is nil
« 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)
Check my ProjectShare site and share your content: FPCShare

winni

  • Hero Member
  • *****
  • Posts: 1616
Re: Object Referrence is nil
« Reply #1 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

Jake012345

  • Sr. Member
  • ****
  • Posts: 253
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Object Referrence is nil
« Reply #2 on: July 14, 2020, 11:10:41 pm »
But theese are here!
I tried to move them back to project folder, but happens same.
« Last Edit: July 14, 2020, 11:20:21 pm by Jake012345 »
Check my ProjectShare site and share your content: FPCShare

winni

  • Hero Member
  • *****
  • Posts: 1616
Re: Object Referrence is nil
« Reply #3 on: July 14, 2020, 11:22:42 pm »
Hi!

Please look into the ZIP-file:

The bmp-files are NOT there!

Winni

Bart

  • Hero Member
  • *****
  • Posts: 3857
    • Bart en Mariska's Webstek
Re: Object Referrence is nil
« Reply #4 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
« Last Edit: July 14, 2020, 11:59:11 pm by Bart »

Bart

  • Hero Member
  • *****
  • Posts: 3857
    • Bart en Mariska's Webstek
Re: Object Referrence is nil
« Reply #5 on: July 14, 2020, 11:49:58 pm »
Some other remarks:
  • Setting Form1.AutoSize to True, makes the form the size of Button1, not what you want.
  • Having 52 cards next to each other, no spacing at all, is a little bit annoying.

Bart

Jake012345

  • Sr. Member
  • ****
  • Posts: 253
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Object Referrence is nil
« Reply #6 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! ;) )
Check my ProjectShare site and share your content: FPCShare

 

TinyPortal © 2005-2018