为什么如果Assigned(ListViewLayers1.Items)然后产生异常

时间:2014-02-19 20:28:06

标签: delphi delphi-xe4

{ Clear ListViewLayers }
  try
    if Assigned(ListViewLayers1.Items) then
      ListViewLayers1.Clear;
  except
    on E: Exception do
    begin
      ShowMessage(E.ClassName + #10#13 + E.Message);
    end;
  end;

如何在尝试调用Clear之前确定列表视图是否为空?

例外是EAccessViolation。但我不明白为什么ListViewLayers1是在设计时创建的,并且可以在应用程序的整个生命周期中的其他时间访问。

EurekaLog 7.0.7.1  

Exception:
--------------------------------------------------------------------------------------------------------------
  2.2 Address: 00D2E79E
  2.5 Type   : EAccessViolation
  2.6 Message: Access violation at address 00D2E79E in module 'FaceBookDesigner.exe'. Read of address 00000000
  2.7 ID     : 20970000
  2.11 Sent  : 0

User:
-------------------------
  3.2 Name : Windows User
  3.3 Email: 

Steps to reproduce:
------------
  8.1 Text: 


Call Stack Information:
-------------------------------------------------------------------------------------------------------------------------------------------------------------
|Methods |Details|Stack   |Address |Module              |Offset  |Unit            |Class              |Procedure/Method                          |Line      |
-------------------------------------------------------------------------------------------------------------------------------------------------------------
|*Exception Thread: ID=10000; Parent=0; Priority=0                                                                                                          |
|Class=; Name=MAIN                                                                                                                                          |
|DeadLock=0; Wait Chain=                                                                                                                                    |
|Comment=                                                                                                                                                   |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Processes Information:
----------------------


Assembler Information:
---------------------------------------------------------------------------------------------------------------------------
; Base Address: $D2E000, Allocation Base: $400000, Region Size: 94208
; Allocation Protect: PAGE_EXECUTE_WRITECOPY, Protect: PAGE_EXECUTE_READ
; State: MEM_COMMIT, Type: MEM_IMAGE
; 
;
; Unit1.TForm1.UpdateGUI (Line=1803 - Offset=8)
; ---------------------------------------------
00D2E738  8B45FC        MOV  EAX, [EBP-4]
00D2E73B  8B80A0030000  MOV  EAX, [EAX+$000003A0]
00D2E741  8B90D0060000  MOV  EDX, [EAX+$000006D0]
00D2E747  8B45FC        MOV  EAX, [EBP-4]
00D2E74A  8B80A0030000  MOV  EAX, [EAX+$000003A0]
00D2E750  E86FBEE6FF    CALL -$194191                   ; ($00B9A5C4) imageenview.TImageEnView.GetLayer
00D2E755  8B8080000000  MOV  EAX, [EAX+$00000080]
00D2E75B  BA20EAD200    MOV  EDX, $00D2EA20             ; ($00D2EA20) Unit1.TForm1.UpdateGUI (Line=1829) ANSI: 'Border'
00D2E760  E81FD26DFF    CALL -$922DE1                   ; ($0040B984) System._LStrEqual
00D2E765  7518          JNZ  +$18                       ; ($00D2E77F) Unit1.TForm1.UpdateGUI (Line=1806)
;
; Line=1804 - Offset=55
; ---------------------
00D2E767  BA34EAD200    MOV  EDX, $00D2EA34             ; ($00D2EA34) Unit1.TForm1.UpdateGUI (Line=1829) UNICODE: 'Replace'
00D2E76C  8B45FC        MOV  EAX, [EBP-4]
00D2E76F  8B8018040000  MOV  EAX, [EAX+$00000418]
00D2E775  8B08          MOV  ECX, [EAX]
00D2E777  FF9120010000  CALL DWORD PTR [ECX+$00000120]
00D2E77D  EB16          JMP  +$16                       ; ($00D2E795) Unit1.TForm1.UpdateGUI (Line=1808)
;
; Line=1806 - Offset=79
; ---------------------
00D2E77F  BA50EAD200    MOV  EDX, $00D2EA50             ; ($00D2EA50) Unit1.TForm1.UpdateGUI (Line=1829) UNICODE: 'Border'
00D2E784  8B45FC        MOV  EAX, [EBP-4]
00D2E787  8B8018040000  MOV  EAX, [EAX+$00000418]
00D2E78D  8B08          MOV  ECX, [EAX]
00D2E78F  FF9120010000  CALL DWORD PTR [ECX+$00000120]
;
; Line=1808 - Offset=101
; ----------------------
00D2E795  8B45FC        MOV  EAX, [EBP-4]
00D2E798  8B80B0030000  MOV  EAX, [EAX+$000003B0]
;
; Line=1808 - Offset=110
; ----------------------
00D2E79E  8B10          MOV  EDX, [EAX]                 ; <-- EXCEPTION
00D2E7A0  FF9200010000  CALL DWORD PTR [EDX+$00000100]
00D2E7A6  8BD8          MOV  EBX, EAX
00D2E7A8  8B45FC        MOV  EAX, [EBP-4]
00D2E7AB  8B80B0030000  MOV  EAX, [EAX+$000003B0]
00D2E7B1  8B80B4020000  MOV  EAX, [EAX+$000002B4]
00D2E7B7  E8282B95FF    CALL -$6AD4D8                   ; ($006812E4) Vcl.TListItems.GetCount
00D2E7BC  48            DEC  EAX
00D2E7BD  3BD8          CMP  EBX, EAX
00D2E7BF  7D17          JGE  +$17                       ; ($00D2E7D8) Unit1.TForm1.UpdateGUI (Line=1808)
00D2E7C1  8B45FC        MOV  EAX, [EBP-4]
00D2E7C4  8B80B0030000  MOV  EAX, [EAX+$000003B0]
00D2E7CA  8B80B4020000  MOV  EAX, [EAX+$000002B4]
00D2E7D0  E80F2B95FF    CALL -$6AD4F1                   ; ($006812E4) Vcl.TListItems.GetCount
00D2E7D5  48            DEC  EAX
00D2E7D6  7F04          JG   +4                         ; ($00D2E7DC) Unit1.TForm1.UpdateGUI (Line=1808)
00D2E7D8  33D2          XOR  EDX, EDX

Registers:
-----------------------------
EAX: 00000000   EDI: 0018FABC
EBX: 00D2C96F   ESI: 00000000
ECX: 0018FAB0   EBP: 0018FAC0
EDX: 00000000   ESP: 0018FAB8
EIP: 00D2E79E   FLG: 00010246
EXP: 00D2E79E   STK: 0018FAC0

Stack:               Memory Dump:
------------------   ---------------------------------------------------------------------------
0018FAFC: 0018FB28   00D2E79E: 8B 10 FF 92 00 01 00 00 8B D8 8B 45 FC 8B 80 B0  ...........E....
0018FAF8: 04641BC0   00D2E7AE: 03 00 00 8B 80 B4 02 00 00 E8 28 2B 95 FF 48 3B  ..........(+..H;
0018FAF4: 06091090   00D2E7BE: D8 7D 17 8B 45 FC 8B 80 B0 03 00 00 8B 80 B4 02  .}..E...........
0018FAF0: 0878A920   00D2E7CE: 00 00 E8 0F 2B 95 FF 48 7F 04 33 D2 EB 02 B2 01  ....+..H..3.....
0018FAEC: 00000000   00D2E7DE: 8B 45 FC 8B 80 58 04 00 00 8B 08 FF 91 80 00 00  .E...X..........
0018FAE8: 00000000   00D2E7EE: 00 8B 45 FC 8B 80 B0 03 00 00 8B 10 FF 92 00 01  ..E.............
0018FAE4: 00000000   00D2E7FE: 00 00 85 C0 7E 17 8B 45 FC 8B 80 B0 03 00 00 8B  ....~..E........
0018FAE0: 00000000   00D2E80E: 80 B4 02 00 00 E8 CC 2A 95 FF 48 7F 04 33 D2 EB  .......*..H..3..
0018FADC: 0878A920   00D2E81E: 02 B2 01 8B 45 FC 8B 80 5C 04 00 00 8B 08 FF 91  ....E...\.......
0018FAD8: 0091D1DC   00D2E82E: 80 00 00 00 8B 45 FC 8B 80 B0 03 00 00 8B 10 FF  .....E..........
0018FAD4: 08EEACA0   00D2E83E: 92 00 01 00 00 8B D8 8B 45 FC 8B 80 B0 03 00 00  ........E.......
0018FAD0: 0018FAFC   00D2E84E: 8B 80 B4 02 00 00 E8 8B 2A 95 FF 48 3B D8 7D 17  ........*..H;.}.
0018FACC: 0040A4CC   00D2E85E: 8B 45 FC 8B 80 B0 03 00 00 8B 80 B4 02 00 00 E8  .E..............
0018FAC8: 0018FB0C   00D2E86E: 72 2A 95 FF 48 7F 04 33 D2 EB 02 B2 01 8B 45 FC  r*..H..3......E.
0018FAC4: 00D2CB35   00D2E87E: 8B 80 60 04 00 00 8B 08 FF 51 50 8B 45 FC 8B 80  ..`......QP.E...
0018FAC0: 0018FAFC   00D2E88E: B0 03 00 00 8B 10 FF 92 00 01 00 00 85 C0 7E 17  ..............~.

2 个答案:

答案 0 :(得分:1)

假设错误是与我们可以看到的代码相关的访问冲突,if语句中唯一的指针解除引用是当您取消引用Self时,以及随后取消引用{{1}时}。因此,结论是您在无效对象实例上调用方法,或者ListViewLayers1是无效对象实例。

如果异常不是这样的访问冲突,那么它是ListViewLayers1属性的getter引发的异常。

没有更多代码或实际的异常细节,很难再说了。

答案 1 :(得分:0)

关闭devexpress dockpanel时,默认行为是它被销毁。这也会破坏你的列表视图,所以如果你在那之后尝试访问它,你会得到一个例外。

因此,在尝试对其项目执行任何操作之前,请务必检查是否已分配listviewlayers1。我甚至不认为你必须检查它的物品属性是否已分配,除非你在列表视图中做了一些奇怪的黑客攻击。