Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi FindComponent für TScrollBox (https://www.delphipraxis.net/14942-findcomponent-fuer-tscrollbox.html)

F.W. 18. Jan 2004 17:22


FindComponent für TScrollBox
 
Hallo!

Ich hab' mal wieder schnell zwischendurch ein Programm gebastelt. Das Programm besteht aus acht ListBoxen und jeweils einem darin befindlichem Bild.

Das Problem ist, das die 8 ListBoxen und Bilder erst zur Laufzeit erzeugt werden.
Wenn ich jetzt auf die Bilder zugreifen will, muss ich ja FindComponent benutzen. Da gibt es eine Zugriffsverletzung.
Delphi-Quellcode:
TImage(FindComponent('Img3'));
Weil die Bilder in den ListBoxen sind, habe ich es damit probiert:
Delphi-Quellcode:
TImage(TScrollBox(FindComponent(SSB)).FindComponent(SI))
Aber da gibt es immernoch Zugriffsverletzungen.

Wie muss ich es machen, damit es keine Zugriffsverletzungen mehr gibt?

MikeS 18. Jan 2004 17:26

Re: FindComponent für TScrollBox
 
Zu welcher Zeit möchtest du denn auf die bilder zugreifen!
beim erstellen, oder erst später??

F.W. 18. Jan 2004 17:42

Re: FindComponent für TScrollBox
 
Im OnShow wird alles erzeugt:
Delphi-Quellcode:
procedure TMain.FormShow(Sender: TObject);
var
 X, Y, I: Integer;
 SB: TScrollBox;
 Img: TImage;
begin
 WindowState := wsMaximized;
 X := 10;
 Y := 65;
 for I := 1 to 8 do begin
 {-----------ListBoxes-------------}
     SB := TScrollBox.Create(Main);
     SB.Name := 'SB'+IntToStr(I);
     SB.Left := X;
     SB.Top := Y;
     SB.Width := 243;
     SB.Height := 300;
     SB.Parent := Main;
 {-----------Images----------------}
//     Img := TImage.Create(FindComponent('SB'+IntToStr(I)));
     Img := TImage.Create(SB);
     Img.Left := 0;
     Img.Top := 0;
     Img.Width := 200;
     Img.Height := 250;
     Img.Parent := SB;
     Img.Tag := I;
     Img.Canvas.Brush.Color := clwhite;
     Img.AutoSize := True;
     Img.OnDragOver := ImgsDragOver;
     Img.OnDragDrop := ImgsDragDrop;

     Inc(X, 253);

     if I = 4 then begin
        X := 10;
        Inc(Y, 340);
     end;
 end;
end;
Und später wenn man auf einen Button klickt, wird auf sie zugegriffen.

Das Bilderladen geht übrigens, allerdings wird das auch über Drag&Drop per TImage(Source) erreicht.

F.W. 18. Jan 2004 19:29

Re: FindComponent für TScrollBox
 
Ich hab's gelöst, ich hatte in der Eile vergessen den Bildern Namen zu zuweißen.
Jetzt mach ich's ganz normal mit FindComponent.

Danke!

[Edit]: Eine Frage noch: Was ist der Unterschied zwischen
Delphi-Quellcode:
 Label := TLabel.Create(ListBox1);
 LAbel.Parent := ListBox1;
und
Delphi-Quellcode:
 Label := TLabel.Create(Self);
 LAbel.Parent := ListBox1;
?


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:57 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