Einzelnen Beitrag anzeigen

Benutzerbild von Danny92
Danny92

Registriert seit: 18. Aug 2014
55 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#15

AW: JPG ohne Resource einfügen

  Alt 4. Okt 2016, 02:05
Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, jpeg, StdCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Button1: TButton;
    Image2: TImage;
    Image3: TImage;
    procedure FormActivate(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure Image2Click(Sender: TObject);
    procedure Image3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure wahl(tuernummer: integer);
    function tuerwahl(autoposition, wahl1: byte): byte;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  gewaehlt: integer = 0;
  tuer: array[1..3] of TJpegImage;
  autoposition: byte;

implementation

{$R *.dfm} {$R es.res}

function TForm1.tuerwahl(autoposition, wahl1: byte): byte;
begin
  if autoposition=wahl1 then
  case autoposition of
  1: result:=Random(2)+2;
  3: result:=Random(2)+1;
  else
    if Random(2)=0
    then result:=1
    else result:=3
  end
  else
  case autoposition of
  1: if wahl1=2 then result:=3 else result:=2;
  3: if wahl1=2 then result:=1 else result:=2;
  else
    if wahl1=1
    then result:=3
    else result:=1
  end
end;

procedure TForm1.wahl(tuernummer: integer);
begin
  if gewaehlt=0 then
  begin
    case tuernummer of
      1: if tuerwahl(autoposition, tuernummer)=2
         then Image2.Picture.Graphic:=tuer[3]
         else Image3.Picture.Graphic:=tuer[3];
      2: if tuerwahl(autoposition, tuernummer)=1
         then Image1.Picture.Graphic:=tuer[3]
         else Image3.Picture.Graphic:=tuer[3];
    else
      if tuerwahl(autoposition, tuernummer)=2
      then Image2.Picture.Graphic:=tuer[3]
      else Image1.Picture.Graphic:=tuer[3];
    end;
    gewaehlt:=tuernummer;
  end else
  begin



  end
end;

procedure TForm1.FormActivate(Sender: TObject);
var
   jpgLogo: TJpegImage;
   RStream: TResourceStream;
   i, j: integer;
begin
   for i:=1 to 3 do
   begin
     RStream := TResourceStream.Create(HInstance, 'A'+IntToStr(i), RT_RCDATA);
     try
        jpgLogo := TJpegImage.Create;
        Try
           jpgLogo.LoadFromStream(RStream);
           tuer[i].LoadFromStream(RStream);
           //tuer[i]:=jpgLogo;
           if i=1 then
           for j:=1 to 3 do
           case j of
            1: Image1.Picture.Graphic := jpgLogo;
            2: Image2.Picture.Graphic := jpgLogo;
           else
             Image3.Picture.Graphic := jpgLogo;
           end
        finally
           //jpgLogo.Free;
        End;
     finally
        RStream.Free;
     end
   end

end;

procedure TForm1.Image1Click(Sender: TObject);
begin
  Wahl(1);
end;

procedure TForm1.Image2Click(Sender: TObject);
begin
  Wahl(2);
end;

procedure TForm1.Image3Click(Sender: TObject);
begin
  Wahl(3);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: integer;
begin
  Randomize;
  autoposition:=Random(3)+1;
  for i:=low(tuer) to high(tuer) do
    tuer[i]:=TJpegImage.Create;
end;

end.
die Fehlermeldungen erscheinen am Ende des OnClick-Ereignis der TImage Komponenten.
  Mit Zitat antworten Zitat