Recent

Author Topic: TBitmap.LoadFromFile can not load .BMP file [SOLVED]  (Read 623 times)

ad1mt

  • Sr. Member
  • ****
  • Posts: 465
    • Mark Taylor's Home Page
TBitmap.LoadFromFile can not load .BMP file [SOLVED]
« on: October 12, 2025, 08:30:39 am »
I'm getting an exception when using TBitmap.LoadFromFile to load a .BMP file
The full code is in the attached zip file, which includes the .BMP file.
Here is a synopsis:
Code: Pascal  [Select][+][-]
  1. const White_Man_File = 'White_Man_1.bmp';
  2. var White_Man:TBitmap;
  3. begin
  4. White_Man:= TBitmap.Create;
  5. try White_Man.LoadFromFile(White_Man_File);
  6. finally
  7.         showmessage('Could not load image file "'+White_Man_File+'"');
  8.         halt;
  9. end;
  10. end.
  11.  
Thanks.
« Last Edit: October 12, 2025, 11:36:45 am by ad1mt »

Thausand

  • Sr. Member
  • ****
  • Posts: 405
Re: TBitmap.LoadFromFile can not load .BMP file
« Reply #1 on: October 12, 2025, 08:51:46 am »
When exception then there is message. Exception message write what wrong more exact.

Also you code have problem. Finally code always run so every time program run have showmessage then make halt (then that can make exception if Lazarus have configured when make exception for halt).
« Last Edit: October 12, 2025, 08:59:31 am by Thausand »

ad1mt

  • Sr. Member
  • ****
  • Posts: 465
    • Mark Taylor's Home Page
Re: TBitmap.LoadFromFile can not load .BMP file
« Reply #2 on: October 12, 2025, 11:19:06 am »
Thanks for your reply.
Stupid copy & paste error  :(
I'm an idiot.
Copy & paste rule no 1: never paste code from an example, without understanding how the code works.

cdbc

  • Hero Member
  • *****
  • Posts: 2473
    • http://www.cdbc.dk
Re: TBitmap.LoadFromFile can not load .BMP file [SOLVED]
« Reply #3 on: October 12, 2025, 11:47:59 am »
Hi
I took the liberty of "Ironing out your Mess"...
Have a look in the attachment...
Regards Benny

eta: ...and here's a screenshot too...
« Last Edit: October 12, 2025, 11:50:59 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6 -> FPC 3.2.2 -> Lazarus 4.0 up until Jan 2025 from then on it's both above &: KDE6/QT6 -> FPC 3.3.1 -> Lazarus 4.99

ad1mt

  • Sr. Member
  • ****
  • Posts: 465
    • Mark Taylor's Home Page
Re: TBitmap.LoadFromFile can not load .BMP file [SOLVED]
« Reply #4 on: October 12, 2025, 12:51:59 pm »
I took the liberty of "Ironing out your Mess"...
Have a look in the attachment...
I can't see any significant difference between your version and mine. Any untidiness in the code I uploaded was probably because the uploaded code was cut out of a much bigger project.
Anyway, I have hit another problem, which I would value help with. If you have time, please look at my next post.
Thanks.

cdbc

  • Hero Member
  • *****
  • Posts: 2473
    • http://www.cdbc.dk
Re: TBitmap.LoadFromFile can not load .BMP file [SOLVED]
« Reply #5 on: October 12, 2025, 12:54:55 pm »
Hi
Take a longer look, then you'll see I've merged the 2 lfm files into one and written the missing eventhandlers etc...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6 -> FPC 3.2.2 -> Lazarus 4.0 up until Jan 2025 from then on it's both above &: KDE6/QT6 -> FPC 3.3.1 -> Lazarus 4.99

wp

  • Hero Member
  • *****
  • Posts: 13219
Re: TBitmap.LoadFromFile can not load .BMP file [SOLVED]
« Reply #6 on: October 12, 2025, 12:56:47 pm »
In cdbc's code, there is "try - except - end" where the part between "except" and "end" is executed only in case of an exception. But in your code, there is "try - finally - end" where the part between "finally" and "end" is executed ALWAYS.

ad1mt

  • Sr. Member
  • ****
  • Posts: 465
    • Mark Taylor's Home Page
Re: TBitmap.LoadFromFile can not load .BMP file [SOLVED]
« Reply #7 on: October 12, 2025, 01:37:45 pm »
I took the liberty of "Ironing out your Mess"...
Thanks for your input.
Have a look in the attachment... this is the bigger project.
Many years ago, I wrote a Daughts playing program in Pascal (aka Checkers in some countries).
It has always been a command-line program, and I've decided to create a nice GUI front-end for it.
This will be my first big GUI Pascal program.
I've attached a zip of the latest version. This only has the GUI front-end code, I will add the playing engine code later.
If you can spot any errors/problems in the project code, I would welcome your input (or anyone else's input)
Thanks.

 

TinyPortal © 2005-2018