Delphi 10.3 使用if多条件例如 if 'a' in ['a', 'b'] 时报错,提示operator not applicable to this operand type;
想将字符串转A码使用
ord(tmp) //tmp:string='a'
时也报错,提示incompatible type
但是直接ord('a') 确没有问题
请教各位大神这是什么原因?看了网上的代码跟我的一模一样的但却没有问题?
想将字符串转A码使用
ord(tmp) //tmp:string='a'
时也报错,提示incompatible type
但是直接ord('a') 确没有问题
请教各位大神这是什么原因?看了网上的代码跟我的一模一样的但却没有问题?
if AnsiChar('a') in ['a', 'b'] then ...
就好了
或者可以使用if CharInSet('a', ['a', 'b']) then ...
var
i: Integer;
begin
if DMADO.ADO考试.IsEmpty then
Exit; if (AnsiChar(Key) in [#13, Char(VK_DOWN)]) and (ActiveControl is TDBEditEh) then
begin
Key := #0;
if not(CharInSet(Key, ['0' .. '9', '.', '-', #8])) then
Key := #0;
if (Key = '.') and (Pos('.', Edit4.text) > 0) then
Key := #0;
tmp: string;
begin
tmp := 'a';
if tmp[1] in ['a', 'b'] then
begin
showmessage('matched');
end;