Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Problem mit ImageList (https://www.delphipraxis.net/16658-problem-mit-imagelist.html)

LoW_FloW 21. Feb 2004 10:22


Problem mit ImageList
 
Ich habe ein Problem mit der ImageList. Ich will Bilder in die Liste laden. Bin ein ziemlicher n00b und habe zuvor auch nix mit ImageListen gemacht :oops: .
Hier der Source :-D :
Delphi-Quellcode:
unit uTest;

interface

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

type
  TForm1 = class(TForm)
    Start: TButton;
    FigurListe: TImageList;
    Label1: TLabel;
    Timer1: TTimer;
    procedure StartClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Bild : TBitmap ;
  BildName : string ;
  i : integer ;

implementation

{$R *.dfm}

procedure TForm1.StartClick(Sender: TObject);
begin
for i := 1 to 2 do
  begin
  Bild.LoadFromFile(IntToStr(i) + '.bmp');
  Bild.Width := 840 ;
  Bild.Height := 560 ;
  FigurListe.Width := 840 ;
  FigurListe.Height := 560 ;
  FigurListe.Masked := false ;
  FigurListe.Add(Bild, nil)
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FigurListe.Free ;
Bild.Free ;
end;

end.
Ich hoffe, mir kann jemand helfen, das wäre wirklich :thuimb:

MikeS 21. Feb 2004 10:31

Re: Problem mit ImageList
 
erläutere dich mal bitte dein problem etwas! tritt ein fehler auf und wenn welcher und wo?

ich glaube nicht das es sinn macht beim erzeugen des formulars den speicher des bildes und der liste freizugeben!

LoW_FloW 21. Feb 2004 10:52

Re: Problem mit ImageList
 
Zitat:

Zitat von MikeS
erläutere dich mal bitte dein problem etwas! tritt ein fehler auf und wenn welcher und wo?

Wenn ich auf Start drücke, kommt der Fehler:
Code:
Im Projekt Test.exe ist eine Exception der Klasse EAccessViolation aufgetreten Meldung: "Zugriffsverletzung bei der Adresse 00401AD1 im Modul Test.exe. Lesen von Adresse 0000000. Prozess wurde angehalten. Mit Einzelne Anweisung oder Start fortsetzten.
Aber ich weiß nicht, was das jetzt bringen soll... :gruebel: :-D

Benedikt 21. Feb 2004 11:07

Re: Problem mit ImageList
 
Die Meldung kommt deshalb, weil du die noch garnicht erzeugte ImageList und das Bild im FormCreate schon wieder freigibst.
Im FormCreate solltest du sie stattdessen Createn und im FormClose freigeben.

Davon ab ist das hier

Delphi-Quellcode:
Bild.LoadFromFile(IntToStr(i) + '.bmp');
unvorsichtig, weil du keinen exakten Pfad angibst.
Wenn das Bild im Programm-Verzeichnis liegt mach:

Delphi-Quellcode:
Bild.LoadFromFile(ExtractFilePath(Application.Exename)+IntToStr(i)+'.bmp');

LoW_FloW 21. Feb 2004 12:12

Re: Problem mit ImageList
 
Zitat:

Zitat von Benedikt
Die Meldung kommt deshalb, weil du die noch garnicht erzeugte ImageList und das Bild im FormCreate schon wieder freigibst.
Im FormCreate solltest du sie stattdessen Createn und im FormClose freigeben.

Danke erstmal :-D , aber wie createt man die TimageList?
FigurListe.Create(A0wner) geht nicht :?

SirThornberry 21. Feb 2004 12:16

Re: Problem mit ImageList
 
Delphi-Quellcode:
FigurListe := Tiimagelist.create(Self);
Für Self kannst du auch "nil" oder halt einen beliebigen owner angeben

LoW_FloW 21. Feb 2004 12:24

Re: Problem mit ImageList
 
thx :-D :-D :-D funtzt soweit!
Jetzt habe ich ein wieder Problem (schlimm mit diesen n00bs, stimmts?)
Wie sage ich der ImageList, das sie ein Bild darstellen soll, brauche ich dafür ein normales Image?
Aus der Delphi-Hilfe, werde ich nicht klar :oops:

SirThornberry 21. Feb 2004 13:15

Re: Problem mit ImageList
 
jup, die imagelist ist nur zum speichern von bildern also ne art container
Delphi-Quellcode:
  Imagelist1.GetBitmap(0, Image1.picture.Bitmap); //lädt das bild aus Imagelist1 (Index 0) in Image1.picture.bitmap)
Nachteil ist das die Imagelist nur bilder bis zu einer bestimmten größe nimmt, also wirst du damit keine desktop-hintergrundbilder kapseln können

LoW_FloW 21. Feb 2004 13:36

Re: Problem mit ImageList
 
Vielen DANK euch allen, geht jetzt alles SUPER :-D :-D :-D :-D :-D


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:06 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz