Autor Beitrag
ZO_orki
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Do 25.05.06 16:18 
Folgendes:
Ich möchte gerne mehrere TImages zur Laufzeit erstellen und ihnen Bilder zuweisen:

ausblenden 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:
var
  bild: Array[1..15] of TImage;

...

procedure ...
begin

for i:=1 to 10 do
begin
  bild[i] := TImage.create(self);
  bild[i].Enabled:=true;
  bild[i].Parent:=start; //start ist die Form
  bild[i].Show; //nicht unbedingt nötig
  bild[i].BringToFront;
  bild[i].AutoSize:=true;
  bild[i].Picture.LoadFromFile('wand.bmp');
  bild[i].Left := 100;
  bild[i].Top := 100;
  bild[i].Free;
end;

...


Was funktioniert hier nicht bzw. was habe ich falsch gemacht, dass kein Bild angezeigt wird???

Schon mal danke im Voraus

Zo_Orki
Moderiert von user profile iconjasocul: Code-Tags durch Delphi-Tags ersetzt
_frank_
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 343
Erhaltene Danke: 1

Win XP
Delphi 3 Prof / Turbo Delphi Explorer
BeitragVerfasst: Do 25.05.06 16:31 
naja, wenn du die TImages wieder freigibst kann nix angezeigt werden ;)

die darfst du erst dann freigeben, wenn du sie nimmer brauchst (z.B. im Formdestroy)

Gruß Frank
ZO_orki Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Do 25.05.06 16:35 
*hm* ich habe es gerade einmal ohne .free ausprobiert... mit demselben Ergebnis

trotzdem thx ;) ich habe vorher nie so recht gewusst, wofür .free gut war
_frank_
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 343
Erhaltene Danke: 1

Win XP
Delphi 3 Prof / Turbo Delphi Explorer
BeitragVerfasst: Do 25.05.06 16:43 
zeig mal den funktionskopf und deine formular deklaration.

evtl musst du auch beim create statt self das form nehmen.
möglicherweise ist ein anderes control davor. ist auch nicht sehr sinnig 15 bilder übereinander zu legen...
evtl. left :=i*100; (oder top oder beides) ;)

Gruß Frank
ZO_orki Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Do 25.05.06 16:57 
ist ne ganz normale formcreate procedure
die procedure heißt start ;)
es ist nur die variable var i:integer; definitert

er startet das programm zwar und es erscheint auch keine fehlermeldung, aber das/die bilder kann ich auch nicht sehen :(


und die bilder werden später noch "verstreut" ;) aufeinanderlegen möchte ich die nicht ^^



ach ja: TImage.Create(start); klappt auch nicht :(
_frank_
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 343
Erhaltene Danke: 1

Win XP
Delphi 3 Prof / Turbo Delphi Explorer
BeitragVerfasst: Do 25.05.06 17:02 
die procedure heist start?? als parent musst du die form-variable nehmen...
mal mein versuch (der funktioniert, bild im programmverzeichnis):

ausblenden 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:
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    bild: Array[1..15] of TImage;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
  for i:=1 to 10 do
  begin
    bild[i] := TImage.create(self);
    bild[i].Parent:=form1; //start ist die Form
    bild[i].AutoSize:=true;
    bild[i].Picture.LoadFromFile(extractfilepath(paramstr(0))+'wand.bmp');
    bild[i].Left := i*bild[i].width;
    bild[i].Top := 100;
  end;
end;

das extractfilepath brauchst du nicht zwingend aber ist sicherer, da sonst das aktuelle verzeichnis verwendet wird. Dieses passt z.B. beim aufruf ordner\test.exe nicht mehr...

HTH Frank
ZO_orki Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Do 25.05.06 17:08 
kann es sein, dass du nen extra bild auf die Form gezeichnet hast? ;)
denn nur dann funktionierts auch bei mir - und ich wäre nebenbei um ein "aha"-erlebnis reicher...

edit: ich seh grad: "bild im programmverzeichnis" :D ok thx, dadurch wird einiges klarer
könntest du trotzdem noch mal erläutern was das genau heißt ;) (bin heute etwas schwer von begriff)


vielen, vielen dank frank :D
_frank_
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 343
Erhaltene Danke: 1

Win XP
Delphi 3 Prof / Turbo Delphi Explorer
BeitragVerfasst: Do 25.05.06 17:11 
öööhmmm, bekommst du schon nen Fehler dass er TImage nicht kennt?
Wenn ja musst du natürlich die ExtCtrls in die uses aufnehmen...

der code ist sonst der einzige in meinem Testproggy

"bild im programmverzeichnis" = "wand.bmp liegt im gleichen ordner wie die exe des programms"
ZO_orki Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Do 25.05.06 17:14 
ok thx hat sich nun vollkommen geklärt :D

noch einmal vielen dank :)