i wrote this code to dynamic create led
var
fLed: Tglhudsprite;
i,fImgSnapNum: integer;
............
for i := 0 to fImgSnapNum - 1 do
begin
fLed := TGLHUDSprite.CreateAsChild(MainForm.Dummy_Sound);
fLed.Name := 'fLed' + IntToStr(i);
fled.Material.MaterialLibrary := MatLib;
fLed.Material.LibMaterialName := 'led';
fLed.Width := fLed.Material.GetActualPrimaryTexture.Image.Width;
fLed.Height := fLed.Material.GetActualPrimaryTexture.Image.Height;
fled.SetSize(18,18);
fled.Position.X := 530 + (i * 30);
fled.Position.Y := 600;
fled.Visible := true;
end;
how can i find and free the fLed glscene objects... ?
Thank you... I use delphi7 and GLScene components...
The obvious way to free the objects is simply to call their Free
method, the same as you'd free any other object. The code shown creates many objects, so you need to have some way of freeing all of them; only the single most recently created object will still be in the fled
variable. The naïve solution to that is simply to keep a list of those objects in some container, such as TObjectList
. Then iterate over the container and free its contents.
You might not need a separate container, though. The owner argument you pass to the sprites' constructor maintains a list of all the things it owns. You can iterate over its Components
array, just like you can with any other descendant of TComponent
.
Finally, since you're assigning the Name
properties of all the objects, you can call Dummy_Sound.FindComponent
to find each sprite component by its name. (And if you're not searching for such dynamically allocated components by name, then there's little reason to assign the Name
property in the first place.)