hola soy nuevo en el foro, tambien programando en delphi y me gustaria que alguien puediera ayudarme.
Estoy realizando una aplicacion donde necesito crear mucho botones en un scrollbox, el problema es que cuando creo demasiados botones marca error de memoria y quisiera ver si alguien sabe como arreglaro o tenga una solucion mi codigo es el siguiente
Código Delphi
[-]
procedure TframeVentas.CrearBotonesProductos(var categoria:Integer);
Var
PosY:Integer;
PosX:Integer;
n:Integer;
i :Integer;
begin
BorrarBtns(ScrollBoxProductos);
if categoria=1 then
begin
lblProductos.Caption:=lblProductos.Caption+' DE ROPA';
end
else
begin
lblProductos.Caption:=lblProductos.Caption+' DE JOYERIA';
end;
CONEXIONES.conexion.IBQuery1.SQL.Clear;
CONEXIONES.conexion.IBQuery1.SQL.Add('select idproductos,nombre_producto from productos where categorias_idcategorias='+inttostr(categoria)+' order by nombre_producto');
CONEXIONES.conexion.IBQuery1.open;
SetLength(BtProductos, CONEXIONES.conexion.IBQuery1.RecordCount) ;
PosY:=0;
PosX:=0;
n:=1;
while not CONEXIONES.conexion.IBQuery1.Eof do
begin
BtProductos[n]:=TButton.Create(self);
with self.BtProductos[n] do
begin
Caption:=CONEXIONES.conexion.IBQuery1.FieldByName('nombre_producto').AsString;
Parent:=ScrollBoxProductos;
Height:=61;
Top:=PosY;
Left:=PosX;
PosY:=PosY+Height+10;
Width:=77;
WordWrap:=true;
OnClick:=ClickBotonProductos;
Name:='btProducto'+IntToStr(n);
tag:=CONEXIONES.conexion.IBQuery1.FieldByName('idproductos').AsInteger;
Font.Name:='DefaultFontDialog1.Font.Name Times New Roman' ;
if n mod 4=0then
begin
PosX:=PosX+Width+10;
PosY:=0;
end;
end;
CONEXIONES.conexion.IBQuery1.Next;
n:=n+1;
end;
end;
procedure TframeVentas.BorrarBtns(ACtrl: TWinControl);
var
i: Integer;
begin
for i:= ComponentCount -1 downto 0 do
if (Components[i].ClassType = TButton)and
(TButton(Components[i]).Parent = ACtrl) then
Components[i].Free;
end;
todo esto lo ejecuto desde un boton y antes de crearlo elimino el contenido del scrollbox para crera los nuevos botones espero alguien me ayude gracias