![]() |
Re: Findcomponent löst Exception aus???
Hi Thorben86,
du sollst das Ergebnis von FindComponent abspeichern, und nicht den Namen des Ergebnisses :zwinker: Als Beispiel:
Delphi-Quellcode:
Greetz
var
c: TComponent; begin c := TComponent(Findcomponent('im_st'+ InttoStr(1) + 'nr1'+ InttoStr(Stapel[1].Anzahl))); c.Name := ... end; alcaeus |
Re: Findcomponent löst Exception aus???
Aso, dabei kommt aber glaub ich die gleiche Exception raus(Es kommt auf jedenfall auc hne Zugriffsverletzung raus)
|
Re: Findcomponent löst Exception aus???
Hmm, also bei einem durchgang klappt es irgendwie jetzt auf einmal. Bei dem 2. durchgang kommt jetz an der anderen stelle ne Exception :gruebel: .
Die Komplette FDunktion:
Delphi-Quellcode:
var Kompo:TComponent;
begin Kompo:=TComponent(Findcomponent('im_st'+ InttoStr(Startstapel) + 'nr' + InttoStr(Stapel[Startstapel].Anzahl)) as TShape); Showmessage(inttostr(2)); //Das wird noch angezeigt, dann kommt die Exct (Findcomponent('im_st'+ InttoStr(Startstapel) + 'nr' + InttoStr(Stapel[Startstapel].Anzahl)) as TShape).Left:= Stapel[Zielstapel].left; (Findcomponent('im_st'+ InttoStr(Startstapel) + 'nr' + InttoStr(Stapel[Startstapel].Anzahl)) as TShape).Top:= Stapel[Zielstapel].Top - (15 * (Anzahl+1)) ; inc(Stapel[Startstapel].Anzahl,-1); inc(Stapel[Zielstapel].Anzahl); Kompo.Name:='im_st'+ InttoStr(Zielstapel) + 'nr' + InttoStr(Stapel[Zielstapel].Anzahl + 1); end; |
Re: Findcomponent löst Exception aus???
es wurde schon zig mal geschrieben das du das Ergebnis von TComponent erstmal auf eine Variable zuweisen sollst und diese dann auf ungleich "nil" überprüfen sollst. Wenn dir FindComponent bei
Delphi-Quellcode:
zurückgibt weil die Komponente mit dem Namen nicht existiert ist klar das dann eine Exception kommt.
(Findcomponent('im_st'+ InttoStr(Startstapel) + 'nr' + InttoStr(Stapel[Startstapel].Anzahl)) as TShape)
richtiger ist
Delphi-Quellcode:
Warum schreibst du überhaupt
var LShape: TShape;
begin LShape := Findcomponent('im_st'+ InttoStr(Startstapel) + 'nr' + InttoStr(Stapel[Startstapel].Anzahl)); if LShape <> nil then begin LShape.Left:=Stapel[Zielstapel].left; end;
Delphi-Quellcode:
Wenn du den Wert den du auf Kompo zugewiesen hast dann nicht nutzt? Zu dem Ist es überflüssig das ganze nach TShape zu casten wenn du es dann der Variablen "kompo" zuweist die vom Typ "TComponent" ist. Besser wäre die Variable "Kompo" als "TShape" zu declarieren und dann mit "Kompo" weiterzuarbeiten und nicht immer wieder "FindComponent" zu nutzen da dies auch ein Performanceeinbruch ist.
Kompo:=TComponent(Findcomponent('im_st'+ InttoStr(Startstapel) + 'nr' + InttoStr(Stapel[Startstapel].Anzahl)) as TShape);
|
Re: Findcomponent löst Exception aus???
Sry, dat ich nit früher antworten konnt, ming I-net war seit 10 aus :? .
Hatte das eben auch schon geänert, aber das bringt mir nichts, da es ne Exception gibt, wenn ich die Procedure zum 2. mal aufrufe(die Wird in ner Rekursiven Procedure mit aufgerufen) und auf die Variable zugreife(also z.b. Kompo.Left) Edit: Beim 2. durchlauf wird Kompo irgendwie nil, nur wieso versteh ich nicht, da dürfte doch eigentlich kein unterschied sein. Jetzt sieht der Text so aus (beim 2. Durchlauf ist Kompo=nil)
Delphi-Quellcode:
var Kompo:TShape;
begin Kompo:=(Findcomponent('im_st'+ InttoStr(Startstapel) + 'nr' + InttoStr(Stapel[Startstapel].Anzahl)) as TShape); if(Kompo=nil)then Showmessage('nil'); Showmessage(inttostr(3)); Kompo.Left:= Stapel[Zielstapel].left - (Kompo.Width div 2);// - (Findcomponent('im_st'+ InttoStr(Startstapel) + 'nr' + InttoStr(Stapel[Startstapel].Anzahl)) as TShape).width; Kompo.Top:= Stapel[Zielstapel].Top - (15 * (Anzahl+1)) ; inc(Stapel[Startstapel].Anzahl,-1); inc(Stapel[Zielstapel].Anzahl); Kompo.Name:='im_st'+ InttoStr(Zielstapel) + 'nr' + InttoStr(Stapel[Zielstapel].Anzahl); Showmessage(Kompo.name); |
Re: Findcomponent löst Exception aus???
Da gibt's IMHO nur 2 Sachen:
|
Re: Findcomponent löst Exception aus???
Ahm, bei Punkt 2 wüsst ich nicht, was ich machen müsste, aber es klappt jetzt auf jedenfall, irgendwie hat der vorher die Anzahl falsch eingelesen.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:07 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz