listview de sağ klik tıklandığında popup menü ile satır eklenmesini sağlıyorum, dün önceden listviewe satır eklemiş olsam veya yeni satır eklediğimde sorun yoktu yani normalde dün çalışan kod bugün ise "access violation: read of address" hatası vermeye başladı...
procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
P: TPoint;
begin
P := GetClientOrigin;
if Button = mbRight then
begin
PopupMenu.Popup(X + P.X + ListView1.Left, Y + P.Y + ListView1.Top);
end;
end;
procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
P: TPoint;
Item: TListItem;
begin
if Button = mbRight then
begin
P.X := X;
P.Y := Y;
P := ClientToScreen(P);
Item := (Sender as TListView).GetItemAt(X, Y);
if Item <> nil then //clicked on item
begin
//you may want to change this, to suit your needs
if listview1.Selected.SubItems.Strings[0] = 'something' then
amenu1.Popup(P.X, P.Y)//your menu on selected item
else
Bmenu1.Popup(P.X, P.Y);//total list view popup menu if none selected item
end
else //no item, show basic menu
Bmenu1.Popup(P.X, P.Y);
end;
end;
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ in god i trust with every movement i do graduated student and looking for knowledge
Popupmenüyü çağırdığınız kodu aşağıdaki kullanarak bir detayı atlamışsınız.
PopupMenu.Popup(X + P.X + ListView1.Left, Y + P.Y + ListView1.Top);
PopupMenu.Popup dediğiniz zaman formunuzun "popupmenu" özelliğini çağırabilirsiniz. Formunuzun popupmenu nil ise hata alırsınız. Doğru kullanım için PopupMenu nesnenizin adını Popmenu veya PopupMenu1 yapın ve kodunuzu da bu şekilde güncelleyin.
Ayrıca PopupMenu'yü aşağıdaki gibi neden direkt bağlamıyorsunuz.