Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi FindComponent Problem ? (https://www.delphipraxis.net/131474-findcomponent-problem.html)

thomas2009 25. Mär 2009 12:13


FindComponent Problem ?
 
Hallo

das suchen nach einem Image innerhalb des Formulars funktioniert aber wenn
ich nach einem Image außerhalb suche, dann erscheint diese Fehlermeldung :
"undeclared TImage" !
Delphi-Quellcode:
image1.picture.Bitmap.Assign(Form2.TImage(FindComponent(Form2.myimage)).Picture.Bitmap);
ich habe natürlich das String "myimage" als Global Variable in Form2 deklariert :
Delphi-Quellcode:
Bublic
myimage: String;
end;

mkinzler 25. Mär 2009 12:16

Re: FindComponent Problem ?
 
Entwder
Delphi-Quellcode:
image1.picture.Bitmap.Assign(TImage(Form2.FindComponent(Form2.myimage)).Picture.Bitmap);
oder besser
Delphi-Quellcode:
image1.picture.Bitmap.Assign((Form2.FindComponent(Form2.myimage) as TImage).Picture.Bitmap);

thomas2009 25. Mär 2009 12:22

Re: FindComponent Problem ?
 
Es hat geklappt. Danke

Einige schreiben dafür eine Funktion :!:
http://www.ureader.de/msg/12266264.aspx

shmia 25. Mär 2009 12:33

Re: FindComponent Problem ?
 
Zitat:

Zitat von thomas2009
Einige schreiben dafür eine Funktion

Und Andere machen den Fehler, nicht zu prüfen, ob FindComponent nicht vielleicht nil zurückliefert.
Delphi-Quellcode:
var
  c : TComponent;
begin
  if Assigned(Form2) then
  begin
    c := Form2.FindComponent(Form2.myimage);
    if Assigned(c) then
      image1.picture.Bitmap.Assign((c as TImage).Picture.Bitmap);
  end;
Noch schlauer wäre natürlich eine Funktion auf TForm2:
Delphi-Quellcode:
function TForm2.GetMyBitmap:TBitmap;
var
  c : TComponent;
begin
  c := FindComponent(myimage);
  if Assigned(c) then
    result := (c as TImage).Picture.Bitmap
  else
    Result := nil;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:19 Uhr.

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