PiedSoftware 3 Posted September 25 I like the way Delphi is getting better at arrays, but there is still a gap in the compiler that let me down. I tried this code in 12.2 to highlight the issue. const nostrings: tarray<string> = []; procedure TForm1.FormShow(Sender: TObject); begin var a: tarray<string>; a := []; if a = nostrings then say('nostrings'); if a = [] then say('it''s blank'); end; procedure TForm1.say(const s: string); begin ListBox1.Items.Add(s); end; This refuses to compile at the line if a = [] then with the error "Incompatible types". But it has no problem with the assignment, so it looks like the programmers have just put this in the "do eventually" basket. Does anyone have any insights into this? --- Mark 1 Share this post Link to post
David Heffernan 2345 Posted September 25 4 hours ago, PiedSoftware said: Does anyone have any insights into this? Delphi doesn't know that you want [] to be an array rather than a set. Because the language has been designed iteratively and there is ambiguity. Delphi literals are a bit of a mess. In any case are you sure that you want to use = with a reference type? That's reference identity and not value identity. You will need to test for Length(a)=0 or not Assigned(a) or a = nil 1 Share this post Link to post