After an error occurs when the image component loads images, how can the program continue to run normally? Development and Application of VCL Components
Http://www.delphi2007.net/DelphiVCL/html/delphi_20061223162659164.html
How can I make Program Continue normal operation?
Thank you!
Try
Try
{Load image}
Except
// No Processing
End;
{Continue your work}
...
Finally
...
End;
I do not want to display a prompt window after an error, but also want the program to continue running.
However, in this case, it does not work:
A bmp image with the suffix JPG
An error message is prompted during image loading.
But I don't want to see any error messages. Is there any way?
The error message is not displayed when an image loading error occurs, but other errors are not displayed.
Use applicationevents and then handle the onexception event
Try
Except
When you perform the following operations, adding try... try t will also report an error.
1. Create a BMP image file on drive C and change it to a.jpg.
2. Create an empty project and add a button and image box.
3. Reference JPEG units.
When try... try t is used, an error is reported. Why? How can this problem be solved?
I found the cause after one afternoon. No error will be reported if the JPEG unit is removed.
Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls, extctrls, JPEG;
Type
Tform1 = Class (tform)
Image1: timage;
Button1: tbutton;
Procedure button1click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.button1click (Sender: tobject );
Begin
Try
Image1.picture. loadfromfile ('C: \ a.jpg ');
Except
End;
End;
End.
Create a BMP image file on drive C and change it to a.jpg
========================================================== ==========================================
It is wrong to manually change BMP to jpg and try to use tsf-image to mount it.
Maozefa (AFU)
Why other errors can be captured by try and the message box is not displayed. However, the Operations just now cannot be captured or the message box cannot be "hidden.
It cannot be ruled out that the user encountered the situation I mentioned when using the program.
Compile it as an EXE file and run it independently. In the IDE environment, you can select Tools> debugger to remove the stop on dephi exceptions option.
I compile it as EXE and the prompt is JPEG Error #42.
I compile it as EXE and the prompt is JPEG Error #42.
========================================================== ==============================
It indicates that this error is not issued through the exception mechanism of Delphi, or is a runtime error, which cannot be captured.
You can use try finally to avoid any errors. Besides, the image call fails, and the image is useless.
: Louis_wh ()
Or an error is reported.
Maozefa (AFA)
However, if JPEG is not referenced, no message is prompted.
In addition, although JPEG is referenced, how can this unit file not be found? Where should I find this stuff (called a unit file? Not found. Is it a class? I don't know where he is)
If JPEG is not referenced, no message is displayed.
========================================================== ==========================================
JPEG. PAS logs on to the jpg and JPEG file formats. When this file is included. when picture loads an image, Tsung image is automatically called according to the login type. To remove this file, you can only use the default tbitmap.
The JPEG. Pas file is in a directory on the d installation disk (if you forget the directory name, you can search for the installation disk) and is not attached to the system.
Thank you very much for maozefa)
I understand.
The file has been searched, and there is still no installation disk. I just want to see Qian Kun in it ......
procedure tform1.button1click (Sender: tobject);
var
B2: tbitmap;
begin
try
B2: = tbitmap. create;
b2.loadfromfile ('C: \ a.jpg ');
image1.picture. assign (B2);
b2.free;
else t
end;
in this way, even if JPEG is referenced, no error is reported, which is the same as maozefa.
Could you tell me the Code specification? Thank you
the above Code is standard in the info \ extras \ JPEG directory of the CD. However, it is strange to manually change the BMP to JPG.
procedure tform1.button1click (Sender: tobject);
var
B2: tbitmap;
begin
try
B2: = tbitmap. create;
try
b2.loadfromfile ('C: \ a.jpg ');
image1.picture. assign (B2);
finally
b2.free;
end;
else t
end;
thank you, maozefa.
however, after manually converting BMP to JPG, it is strange.
----------
some images I downloaded from the Internet are suffixed by a mess, for example, GIF is changed to JPG, JPG is changed to BMP, and so on. Very strange. I don't know why.
for this reason. So much.