Pomoc w rozpoznaniu błędu

Pisałem program konwertujący bitmapy na JPEG lub odwrotnie. Tak wygląda:

s2g08m.jpg

Jednak po wczytaniu obrazu, wybraniu typu konwersji i kliknięciu przycisku Konwertuj pokazuje się taki błąd:

lbqpv.jpg

Nie mam pojęcia gdzie zrobiłem błąd. Proszę o pomoc. To kod programu:

unit Unit9;


interface


uses

  Windows, Messages, JPEG, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ExtCtrls, StdCtrls, ExtDlgs;


type

  TForm2 = class(TForm)

    Image1: TImage;

    OpenPictureDialog1: TOpenPictureDialog;

    SavePictureDialog1: TSavePictureDialog;

    Button2: TButton;

    Button1: TButton;

    Label1: TLabel;

    RadioGroup1: TRadioGroup;

    procedure Button1Click(Sender: TObject);


    procedure Button2Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;


var

  Form2: TForm2;

  Bitmap: TBitmap;



implementation


{$R *.dfm}


procedure TForm2.Button1Click(Sender: TObject);

begin

if openpicturedialog1.execute

then image1.picture.loadfromfile(openpicturedialog1.filename);

Button2.Enabled:= True;

end;



procedure TForm2.Button2Click(Sender: TObject);


var

  JPEGImage: TJPEGImage;

  Bitmap: TBitmap;


       begin

       case RadioGroup1.ItemIndex of

       0:

  try

    JPEGImage:=TJPEGImage.Create;

    JPEGImage.CompressionQuality:=80;

    JPEGImage.Assign(Bitmap);

    if SavePictureDialog1.Execute then

      JPEGImage.SaveToFile(SavePictureDialog1.FileName);

      Label1.Caption:='Done!';


  finally

    Bitmap.Free;

    JPEGImage.Free;


end;


1:

    try

    Bitmap:=TBitmap.Create;

    with Bitmap do

    begin

      PixelFormat:=pf24bit;

      Height:=JPEGImage.Height;

      Width:=JPEGImage.Width;

      Canvas.Draw(0,0, JPEGImage);

    end;

    if SavePictureDialog1.Execute then

      Bitmap.SaveToFile(SavePictureDialog1.FileName);


  finally

    Bitmap.Free;

    JPEGImage.Free;

  end;

end;

         end;




end.
    with Bitmap dobegin:=pf24bit;Height:=JPEGImage.Height;Width:=JPEGImage.Width; [/code]



[b]JPEGImage[/b] - nie zainicjalizowana referencja do klasy

Dzięki, to już coś.

pod case 1: wystarczy

if SavePictureDialog1.Execute then image1.picture.Bitmap.SaveToFile(SavePictureDialog1.FileName); [/code]

i nic więcej.

Teraz mi podkreśla 4. od końca end na czerwono :frowning:

Sformatuj kod po ludzku to zobaczysz gdzie end; zapomniałeś lub zbędny postawiłeś.

Albo daj cały kod to ktoś ci może wskaże (o ile odruchy wymiotne nie zdominują :stuck_out_tongue: ), ale i tak lepiej sformatować.

Tak to wygląda:

Bo masz całego tego try wywalić, wierszy 70-85 włącznie. Ten kod co podałem to zamiast całości przypadku BMP.

PS: Nadał przypominam o formatowaniu kodu.