Autor Beitrag
namX
Hält's aus hier
Beiträge: 6

Windows Vista Ultimate x64
Delphi 2005 Personal
BeitragVerfasst: Fr 27.10.06 23:16 
Hallo Leute,

ich will in meinem Formular per Knopfdruck dynamisch viele TImage-Komponenten erzeugen und in sie ein beliebiges Bild laden.
Hier mein Code wie er jetzt z.Zt. ist:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
var Durchläufe  : Integer;
    Reihe       : Array of Integer;
    Bilder      : Array of TImage;

/////////////////////////////////////////////////////

procedure Ausgabe(Reihe : Array of Integer; Durchläufe : Integer);
var TempInt : Integer;
begin

  SetLength(Bilder, Durchläufe);

  for TempInt:=1 to Durchläufe do

    begin

      with Bilder[TempInt-1].Create(Self) do

        begin

            Parent:=Self;
            Width:=50;
            Height:=50;
            Left:=20;
            Top:=50+(TempInt*50);
            Picture.LoadFromFile('\Pics\'+IntToStr(Reihe[TempInt-1])+'.jpg');

        end;

    end;

end;


Das Problem ist das Delphi hier als AOwner "Self" nicht annimmt! :-(
Hoffe ihr könnt mir helfen!

MfG namX

_________________
Hier sollte eigentlich eine Signatur stehen!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.10.06 23:21 
Moin und :welcome: im Forum!

Wenn du die TImage-Komponenten gar nicht auf dem Formular anzeigen willst, dann wäre vermutlich TBitmap besser (und das braucht auch keinen Owner ;)).

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
namX Threadstarter
Hält's aus hier
Beiträge: 6

Windows Vista Ultimate x64
Delphi 2005 Personal
BeitragVerfasst: Fr 27.10.06 23:24 
@Narses: Doch ich will sie eigentlich auf dem Formular anzeigen, mach ich da z.Zt. etwa derbe was falsch?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.10.06 23:25 
Moin!

user profile iconnamX hat folgendes geschrieben:
Doch ich will sie eigentlich auf dem Formular anzeigen

Gleichzeitig? ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
namX Threadstarter
Hält's aus hier
Beiträge: 6

Windows Vista Ultimate x64
Delphi 2005 Personal
BeitragVerfasst: Fr 27.10.06 23:28 
Jop, sie sollen halt untereinander sein und dann nen Bild zeigen ...
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.10.06 23:34 
Moin!

OK, dann ist das in Ordnung so (war nur zur Sicherheit). ;)

Jetzt zu den Problemen mit deinem Code:
a) Die Prozedur ist keine Methode der Formularklasse, deshalb ist innerhalb der Prozedur "Self" nicht bekannt.

b) Du kannst in ein TImage so ohne weiteres keine JPGs laden. Such mal hier im Forum ein bischen, dann siehst du auch, wie man JPGs laden kann. Wenn du´s erstmal einfach haben willst, dann mußt du BMPs nehmen. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
namX Threadstarter
Hält's aus hier
Beiträge: 6

Windows Vista Ultimate x64
Delphi 2005 Personal
BeitragVerfasst: Fr 27.10.06 23:43 
Also die beiden Probleme sind gelöst, hab jetzt .bmp's und self geht auch.
Nur hab ich jetzt beim ausführen eine AccessViolation bei der Zeile:
ausblenden Delphi-Quelltext
1:
with Bilder[TempInt-1].Create(Self) do					

Also scheint da doch noch was zu klemmen, jmd. ne Idee?

MfG namX
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.10.06 23:47 
Moin!

Ja, klar. ;) Du mußt die erzeugte Instanz der Image-Komponente ja auch in das Array schreiben... :D
ausblenden Delphi-Quelltext
1:
2:
3:
for TempInt := 1 to Durchläufe do begin  
  Bilder[TempInt-1] := TImage.Create(Self);
  with Bilder[TempInt-1] do begin

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
namX Threadstarter
Hält's aus hier
Beiträge: 6

Windows Vista Ultimate x64
Delphi 2005 Personal
BeitragVerfasst: Fr 27.10.06 23:54 
Ah! Vielen herzlichen Dank, es funktioniert!
Hatte Arrays erst vor kurzem im Unterricht und das ganze mit Komponenten
wie TImage ist mir neu aber so bin ich jetzt etwas klüger! :-)

MfG namX