Ir al contenido


Foto

[RESUELTO] Una duda que no viene en la ayuda de Delphi... (Delphi 6, WinXP)


  • Por favor identifícate para responder
5 respuestas en este tema

#1 TiammatMX

TiammatMX

    Advanced Member

  • Miembros
  • PipPipPip
  • 1.750 mensajes
  • LocationUniverso Curvo\Vía Láctea\Sistema Solar\Planeta Tierra\América\México\Ciudad de México\Xochimilco\San Gregorio Atlapulco\Home

Escrito 19 septiembre 2011 - 05:38

Buena tarde, jóvenes y jóvenas...

Resulta que estoy programando una aplicación que más o menos va así... Imagen Enviada(Observar la imagen adjunta, por favor)

Notarán el panel de enmedio, es un TListView que ya contiene la funcionalidad que con doble click sobre un elemento, lo transfiere al panel a su derecha.



delphi
  1. procedure TfrmIntrfz.lstvewSbctgrsDblClick(Sender: TObject);
  2. var
  3.   iIndc : integer;
  4.   bExst : boolean;
  5. begin
  6.   if lstvewSbctgrs.Items.Count > 0 then
  7.   begin
  8.     bExst := False;
  9.     for iIndc := 0 to lstboxRbrs.Items.Count -1 do
  10.       if lstvewSbctgrs.ItemFocused.Caption = lstboxRbrs.Items.Strings[iIndc] then
  11.         bExst := True;
  12.  
  13.     if NOT bExst then
  14.     begin
  15.       lstboxRbrs.Items.Add(lstvewSbctgrs.ItemFocused.Caption);
  16.       bitbttnActlzrRprt.Enabled := True AND EsPropietario(iIdntfcdrRprt);
  17.       bHaCambiado := True;
  18.     end;
  19.     trevewCtgrsClick(Self);
  20.   end;
  21. end;



PPPEEERRROOOOOOOOO..., y como todo en ésta vida tiene un "pero", resulta que si el usuario da un doble click FUERA del texto (es decir, sin tenerlo enfocado), tira una violación de acceso por que entra la función de doble click e intenta procesar un valor nulo...

La pregunta es, ¿cómo puedo evaluar el contenido del doble click dentro del TListView, permitiéndome "cachar" el doble click nulo o sin valor procesable? Añadiré que ya intenté evaluar NIL, NULL, vacío y todos los contenidos que me parecieron podrían caber en la condición, pero el problema se repite...

Como siempre, agradezco de antemano su colaboración para resolver éste problema.

Archivos adjuntos


  • 0

#2 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 19 septiembre 2011 - 08:16

Lo que pasa estimado amigo, es que e Items.Count siempre te va a retornar > a cero, por la sencilla razón de que es la cantidad de elementos que contiene el listview. Para eso tienes que utilizar la propiedad SelCount mas o menos así:



delphi
  1. procedure TForm1.ListView1DblClick(Sender: TObject);
  2. var
  3.   iIndc : integer;
  4.   bExst : boolean;
  5. begin
  6.   if lstvewSbctgrs.SelCount > 0 then
  7.   begin
  8.     bExst := False;
  9.     for iIndc := 0 to lstboxRbrs.Items.Count -1 do
  10.       if lstvewSbctgrs.ItemFocused.Caption = lstboxRbrs.Items.Strings[iIndc] then
  11.         bExst := True;
  12.  
  13.     if NOT bExst then
  14.     begin
  15.       lstboxRbrs.Items.Add(lstvewSbctgrs.ItemFocused.Caption);
  16.       bitbttnActlzrRprt.Enabled := True AND EsPropietario(iIdntfcdrRprt);
  17.       bHaCambiado := True;
  18.     end;
  19.     trevewCtgrsClick(Self);
  20.   end;
  21. end;



Intenta y nos comentas.

SaludOS
  • 0

#3 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 19 septiembre 2011 - 09:35

De la ayuda de Delphi


Items (protected)  Contains the list of items displayed by the list view. 

SelCount (public)  Specifies the number of selected items in the list view.



TCustomListView.SelCount Property

Specifies the number of selected items in the list view.

Class
TCustomListView

Syntax

property SelCount: Integer read GetSelCount;

Description

Read SelCount to determine the number of items that are currently selected. When SelCount is 1, use the Selected property to access the selected item. To locate the selected items when SelCount is greater than one, check the Selected property of the list items, beginning with the item specified by the Selected property.

Note: SelCount can only exceed 1 if the MultiSelect property is true.


SaludOS

  • 0

#4 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 20 septiembre 2011 - 12:19

Evidentemente sin poder probar nada, he realizado un pequeño cambio:


delphi
  1. procedure TfrmIntrfz.lstvewSbctgrsDblClick(Sender: TObject);
  2. var
  3.   iIndc : integer;
  4. begin
  5. if lstvewSbctgrs.SelCount > 0 then
  6.   begin
  7.     if NOT (lstvewSbctgrs.Selected.Caption = lstboxRbrs.Items.Strings[iIndc])  then
  8.     begin
  9.       lstboxRbrs.Items.Add(lstvewSbctgrs.ItemFocused.Caption);
  10.       bitbttnActlzrRprt.Enabled := True AND EsPropietario(iIdntfcdrRprt);
  11.       bHaCambiado := True;
  12.     end;
  13.     trevewCtgrsClick(Self);
  14.   end;
  15. end;



Espero que te sirva.

Saludos.
  • 0

#5 Sergio

Sergio

    Advanced Member

  • Moderadores
  • PipPipPip
  • 1.092 mensajes
  • LocationMurcia, España

Escrito 20 septiembre 2011 - 02:43

Puedes usar el pixel donde se hace el click (Mouse.CursorPos) y pedirle al ListView que te diga el item mas cercano a ese punto con la funcion GetNearestItem:

Call GetNearestItem to locate a list item from a position specified in pixel coordinates relative to the top left corner of the list view. GetNearestItem starts looking at the position specified by the Point parameter, and moves in the direction indicated by the Direction parameter until it locates a list item. If no item is found, GetNearestItem returns nil (Delphi) or NULL (C++).

Solo tienes que convertir las coordenadas de pantalla de Mouse.CursorPos a coordenadas relativas a la esquina de tu ListView, y eso es solo hacer lstvewSbctgrs.ScreenToClient(Mouse.CursorPos).

Respecto de la direccion de busqueda, dile que apunte para arriba (sdAbove) y listo, asi, si pinchan abajo te devuelve el ultimo de la lista.



delphi
  1. Clickado:= lstvewSbctgrs.GetNearestItem(ScreenToClient(Mouse.CursorPos), sdAbove);
  2. if Assigned(Clickado) then begin


  • 0

#6 TiammatMX

TiammatMX

    Advanced Member

  • Miembros
  • PipPipPip
  • 1.750 mensajes
  • LocationUniverso Curvo\Vía Láctea\Sistema Solar\Planeta Tierra\América\México\Ciudad de México\Xochimilco\San Gregorio Atlapulco\Home

Escrito 20 septiembre 2011 - 08:33

¡¡Gracias, chavos!!, mi anciano pellejo sigue completo gracias a ustedes.
  • 0




IP.Board spam blocked by CleanTalk.