Autor Beitrag
idefix123456
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Sa 28.08.10 10:37 
Hallo,

Ich bin neu hier, und habe auch schon eine Frage wegen eines Problems, bei dem ich einfach nicht weiterkomme!

Ich habe gestern folgende Delphi procedure erstellt um Schnell und Einfach Bilder Dynamisch zur Laufzeit einzufügen!

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:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
procedure image_simple_load(str: string);
  var
    img: Timage;
    i: integer;
    result, value, wert: string;
begin
  if not (Copy(Trim(str), length(str)) = ';'then begin str := str + ';'end;  // Überprüfe ob das letzte Zeichen ein ; ist, wenn nein dann setze es!

    img := TImage.Create(nil);
    img.Parent := Form1;    // Hier das 'Form1' Anpassen

  for i := 2 to count_chars(str, ';')+1 do begin
    result := Trim(split(str,';',i));
    result := result + ':';
    value := split(result,':',2);
    wert := split(result,':',3);

    if value = 'name' then begin
      img.Name := wert;
    end
    else if value = 'path' then begin
      img.Picture.loadfromfile(wert);
    end
    else if value = 'width' then begin
      img.Width := StrToInt(wert);
    end
    else if value = 'height' then begin
      img.Height := StrToInt(wert);
    end
    else if value = 'visible' then begin
      img.Visible := StrToBool(wert);
    end
    else if value = 'left' then begin
      img.Left := StrToInt(wert);
    end
    else if value = 'top' then begin
      img.Top := StrToInt(wert);
    end
    else if value = 'stretch' then begin
      img.Stretch := StrToBool(wert);
    end;

  end;
end;


EINFÜGREN!!!!
ausblenden Delphi-Quelltext
1:
image_simple_load('left:100; top:50; width:400; height:400; visible:true; name:bild1; path:t.bmp; stretch:false');					


Jetzt benötige ich eine 2te funktion bei der überprüft werden soll, ob das Bild Name: "bild1" existiert! wie mache ich das???

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function image_is_loaded(str: string): Boolean;
begin
  if BILD NAME bild1 EXISTIERT then begin
    LIEFTERT true
  end
  else begin
    LIEFERT false
  end;
end;


Währe dankbar über eine Antwort


Moderiert von user profile iconNarses: Topic aus Multimedia / Grafik verschoben am So 29.08.2010 um 12:57


Zuletzt bearbeitet von idefix123456 am Sa 28.08.10 11:11, insgesamt 1-mal bearbeitet
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Sa 28.08.10 10:58 
Hallo und :welcome: im Delphi-Forum!

Als erstes würde ich dich bitten die [delphi][/delphi]-Tags zu verwenden um deinen Quelltext hier im Forum besser lesbar zu machen.

Ich würde ganz einfach bei der Erstellen-Prozedur den Namen vom Image setzen (á la Img.Name := 'newLoadedImage'). Damit jetzt folgendes funktioniert musst du das hier
ausblenden Delphi-Quelltext
1:
TImage.Create(nil)					

auf das hier ändern
ausblenden Delphi-Quelltext
1:
TImage.Create(Form1)					


Dann kannst du einfach mit FindComponent die Komponente suchen. Dann kannst du nämlich sowas machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
function image_is_loaded(str: string): Boolean; 
begin
  if assigned(Form1.FindComponent(str)) then
    result := true
  else result := false;
end;

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
idefix123456 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Sa 28.08.10 11:17 
Vielen Dank hat funktioniert!