I have a program that when it starts it reads the database and creates panels inside a scrollbox, and inside the created panels are also created images that start with visible = false.
Now the problem starts because I want when I hover over the panel the image of that panel is visible and when the mouse comes off it becomes invisible. But when I hover over any panel their images are not visible but an image from another panel, always the same panel, no matter if I close the program and he opens it again.
I use lazarus 1.8.2 on windows 7.
Code to create panels and images:
procedure TfArrastarSoltarDois.FormShow(Sender: TObject);
var
//img : TImage;
pan : TPanel;
iConPan, iHei, i : Integer;
begin
box_AFazer.DestroyComponents;
box_Finalizado.DestroyComponents;
box_Andamento.DestroyComponents;
i := 0;
With dm.qry_TarefaDois do
Begin
Close;
SQL.CLEAR;
SQL.ADD('SELECT * FROM TB_TAREFA');
Open;
FetchAll;
First;
iHei := 50;
While not eof do
Begin
inc(i);
With fArrastarSoltarDois do
Begin
if FieldByName('SITUACAO').AsString = 'TAREFA A FAZER' then
Begin
iConPan := box_AFazer.ControlCount;
pan := TPanel.Create(box_AFazer);
pan.Parent := box_AFazer;
end
else if FieldByName('SITUACAO').AsString = 'EM ANDAMENTO' then
Begin
iConPan := box_Andamento.ControlCount;
pan := TPanel.Create(box_Andamento);
pan.Parent := box_Andamento;
end
else if FieldByName('SITUACAO').AsString = 'FINALIZADO' then
Begin
iConPan := box_Finalizado.ControlCount;
pan := TPanel.Create(box_Finalizado);
pan.Parent := box_Finalizado;
end;
pan.Align := alTop;
pan.Alignment := taLeftJustify;
pan.Top := (iConPan * iHei) + 1;
pan.Name := 'pan_'+IntToStr(i);
pan.Color := clWhite;
pan.Height := iHei;
pan.Caption := FieldByName('TAREFA').AsString;
pan.DragKind := dkDock;
pan.DragMode := dmAutomatic;
pan.BorderSpacing.Bottom := 10;
pan.BorderSpacing.Top := 10;
pan.BorderSpacing.Left := 10;
pan.BorderSpacing.Right := 10;
pan.OnEndDock := @Panel2EndDock;
pan.OnMouseDown := @Panel2MouseDown;
pan.OnMouseEnter := @Panel7MouseEnter;
pan.OnMouseLeave := @Panel7MouseLeave;
pan.OnEnter := @Panel7Enter;
img := TImage.Create(pan);
img.Parent := pan;
img.Name := 'img_'+IntToStr(i);
img.Top := 7;
img.Left := 276;
img.Width := 38;
img.Height := 38;
img.Picture.LoadFromFile('C:\Users\sergio\Downloads\editar.png');
img.OnClick := @Panel2Click;
img.OnMouseEnter := @Panel7MouseEnter;
img.OnMouseLeave := @Panel7MouseLeave;
img.Visible := False;
end;
Next;
end;
end;
end;
Code to make visible:
procedure TfArrastarSoltarDois.Panel7MouseEnter(Sender: TObject);
begin
TPanel(Sender).color := $00FBFBFB;
img.Visible := True;
end;
Code to make invisible :
procedure TfArrastarSoltarDois.Panel7MouseLeave(Sender: TObject);
begin
TPanel(Sender).color := clWhite;
img.Visible := False;
end;
if anyone knows how to solve this error thank you