Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Findcomponent löst Exception aus??? (https://www.delphipraxis.net/31778-findcomponent-loest-exception-aus.html)

Thorben86 13. Okt 2004 18:37


Findcomponent löst Exception aus???
 
Hi,
Ich will auf eine Image-Komponente mit Findcomponent zugreifen. Da dies jedoch immer eine Exception ausgelöst hat, hab ich 2 Showmessages an den Anfang gesetzt. Die erste wird angezeigt und dann kommt ne Exception(Ungültige Typenumwandlung)

Der Name der Komponente ist im_st1nr1.
Stapel[1].Anzahl ist auch 1.
Hab ich irgend einen Fehler übersehen?, oder warum klappt das nicht?
Delphi-Quellcode:
showmessage('s');
showmessage((Findcomponent('im_st'+ InttoStr(1) + 'nr1'+ InttoStr(Stapel[1].Anzahl) ) as TImage).name);
Edit: Es kommt Ne Exception(Ungültige Typenumwandlung), nicht zugriffsverletzung

omata 13. Okt 2004 18:54

Re: Findcomponent löst Exception aus???
 
Moin,

wenn FindComponent die Komponente nicht findet, wird ein nil-Zeiger zurückgegeben.
Du solltest also immer prüfen, ob FindComponent auch eine Komponente liefert.

also...

Delphi-Quellcode:
var Image:TImage;
begin
  Image:=Findcomponent('im_st'+ InttoStr(1) + 'nr1'+ InttoStr(Stapel[1].Anzahl)) as TImage;
  if assigned(Image) then
    showmessage(Image.name);
end;
Ausserdem solltest du, wenn du schon Text mit einer ShowMessage ausgibst vielleicht den String ausgeben, den du an FindComponent übergibst, dann würdest du nämlich auch bestimmt sehen, dass die Komponente du du finden möchtest nicht existiert.

MfG
Thorsten

Thorben86 13. Okt 2004 19:40

Re: Findcomponent löst Exception aus???
 
Ja, das könnt ich machen, aber das hilft mir bei meinem problem auch nicht, da die Komponente ja vorhanden ist.

alcaeus 13. Okt 2004 19:44

Re: Findcomponent löst Exception aus???
 
Hi Thorben86,

Delphi-Quellcode:
showmessage((Findcomponent('im_st'+ InttoStr(1) + 'nr1'+ InttoStr(Stapel[1].Anzahl) ) as TImage).name);
Überprüf mal ob die Kompo überhaupt ein Image ist, also z.B. so:
Delphi-Quellcode:
var
  c: TObject;
begin
  c := Findcomponent('im_st'+ InttoStr(1) + 'nr1'+ InttoStr(Stapel[1].Anzahl));
  if c is TImage then
    ShowMessage(TImage(c).Name);
end;
Greetz
alcaeus

Thorben86 13. Okt 2004 19:50

Re: Findcomponent löst Exception aus???
 
Thx @ alcaeus: Ich hab jetzt das Problem gefunden, ich hatte die Images durch Shapes ersetzt :wall: :wall: :wall: :oops:

:dp:

Thorben86 13. Okt 2004 19:54

Re: Findcomponent löst Exception aus???
 
Aber jetzt klappt es irgendwie nicht, den Namen davon dann umzuändern.
Klappt das generell nicht oder hab ich schon wieder nen Fehler eingebaut?

Delphi-Quellcode:
(Findcomponent('im_st'+ InttoStr(Startstapel) + 'nr' + InttoStr(Stapel[Startstapel].Anzahl)) as TShape).Name := 'im_st'+ InttoStr(Zielstapel) + 'nr' + InttoStr(Stapel[Zielstapel].Anzahl + 1);

alcaeus 13. Okt 2004 19:55

Re: Findcomponent löst Exception aus???
 
Hi Thorben86,

sag mal was denn nicht funktioniert. Gibts eine Fehlermeldung? AV?

Greetz
alcaeus

Thorben86 13. Okt 2004 20:02

Re: Findcomponent löst Exception aus???
 
Sry, es kommt ne Exception, dass es eine Zugriffsverletzung gibt.

alcaeus 13. Okt 2004 20:05

Re: Findcomponent löst Exception aus???
 
Hi Thorben86,

versuch mal, das Ergebnis von FindComponent in einer Variable abzuspeichern und anschließend den Namen zu ändern. Vielleicht gibts Probleme, weil du ja indirekt der Funktion was zuweist.

Greetz
alcaeus

Thorben86 13. Okt 2004 20:08

Re: Findcomponent löst Exception aus???
 
Ahmm, könntest du vielleicht mal en beispiel machen, wie ich das mache, weil wenn ich den dateinamen auf ner Variable hab, kann ich den zwwar auf der variable ändern, aber wie änder ich den dann bei der Kompo


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:36 Uhr.
Seite 1 von 2  1 2      

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