Home > Back-end >  Delphi if in and word function problem
Delphi if in and word function problem

Time:11-08

Delphi 10.3 use if many conditions such as if 'a' (' a ', 'b') in The Times wrong, prompt the operator not applicable to this operand type;
Want to transfer the string A code using the
The word (TMP)//TMP: string='a'
When an error also, prompt incompatible type
But direct word (' a ')
no problemConsult everybody a great god what reason is this? Look at the online code with me the same but there is no problem?

CodePudding user response:

On word problems have been settled by https://blog.csdn.net/xufeichen/article/details/4480697, but if we aren't

CodePudding user response:

10.2 is ok, but cheap, there is a warning that
If AnsiChar (' a ') in [' a ', 'b'] then...
It's good that
Or you can use the if CharInSet (' a '/' a ', 'b') then...

CodePudding user response:

But the there is a warning

CodePudding user response:

Thanks to the upstairs to answer, can't, very embarrassed, is the version of the problem? I used to use 10.1 also is such, can only be used every time more than N and connection

CodePudding user response:

Never heard of CharInSet (' a ', [' a ', 'b']) no...

CodePudding user response:

To try a KeyPress events:

Procedure TFormMain. DBEditEh4KeyPress (Sender: TObject; Var Key: Char);
Var
I: Integer;
The begin
If DMADO. ADO exam. IsEmpty then
The Exit;

If (AnsiChar (Key) in [# 13, Char (VK_DOWN)]) and (ActiveControl is TDBEditEh) then
The begin
Key:=# 0;

CodePudding user response:

Little monkey is 10.3, don't know why I can't ~ ~ ~

CodePudding user response:

This can also
If not (CharInSet (Key, [' 0 '... '9', '. ', '-', # 8])) then
Key:=# 0;
If (Key=') and (Pos ('. ', Edit4) text) & gt; 0) then
Key:=# 0;

CodePudding user response:

Is not scientific, D7 and D10 can test pass, the complete code is what?

Var
TMP: string;
The begin
TMP:='a';
If TMP [1] in [' a ', 'b'] then
The begin
Showmessage (' matched ');
The end;

CodePudding user response:

CharInSet is high version of the Delphi advocate, in char constants have WideChar AnsiChar and ambiguity

CodePudding user response:

CharInSet is also used in inside, just to avoid the direct use of character literals compiler warnings that appear

CodePudding user response:

Are directly using pos function to determine whether a string in the string b, also is useless to the building Lord that kind of method
  • Related