Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It depends on your Item.SomeProperty type. If it is Variant, or if there is a variant to be evaluated before it, it will be evaluated and cause AV.</p> <p>Edit : Forget to mention the workaround : If the SomeProperty is Variant type, you can use </p> <pre><code> if Assigned(Item) and StrToBool(Item.SomeProperty) then </code></pre> <p>It do spend some time to convert the variable to String then back to boolean but at lease it can satisfy all cases of being true / false / non-existence. </p> <p>Below is a test case for you to see :</p> <pre><code>unit Unit4; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Generics.Collections; type TTestObj = class public V : Variant; I : Integer; end; TForm4 = class(TForm) btn1: TButton; btn2: TButton; btn3: TButton; procedure btn1Click(Sender: TObject); procedure btn2Click(Sender: TObject); procedure btn3Click(Sender: TObject); private { Private declarations } public { Public declarations } TOV : TTestObj; end; var Form4: TForm4; implementation {$R *.dfm} procedure TForm4.btn1Click(Sender: TObject); begin if Assigned(TOV) and (TOV.I = 10) then ShowMessage('You will never see this though no AV!'); end; procedure TForm4.btn2Click(Sender: TObject); begin if Assigned(TOV) and StrToBool(TOV.V) then ShowMessage('You will not see AV with StrToBool!'); if Assigned(TOV) and TOV.V then ShowMessage('You will never see this but AVed!'); end; procedure TForm4.btn3Click(Sender: TObject); var V : Variant; begin V := False; if Assigned(TOV) and V and (TOV.I = 10) then ShowMessage('You will see AV!'); end; end. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload