Thema: Delphi FindComponent Problem ?

Einzelnen Beitrag anzeigen

shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#4

Re: FindComponent Problem ?

  Alt 25. Mär 2009, 12:33
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;
Andreas
  Mit Zitat antworten Zitat