Recent

Author Topic: and operator  (Read 1527 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 258
and operator
« on: July 02, 2022, 01:04:56 pm »
Code: Pascal  [Select][+][-]
  1.  if (PanelRegexModifiers.Controls[Cnt].Caption = 'I') and
  2.            ((PanelRegexModifiers.Controls[Cnt] as TCheckBox).Checked = true)
  3.        then
  4.        begin
  5.          // Shows 'S' or whatever, but should be here only if it was 'I'
  6.          showmessage(PanelRegexModifiers.Controls[Cnt].Caption);
  7.        end
  8.        else
  9.        begin
  10.           //Shows 'S' or whatever, but should be here only if it was 'I'
  11.          showmessage(PanelRegexModifiers.Controls[Cnt].Caption);
  12.        end;  
  13.  
  14.  
  15.  

?
lazarus 3.2-fpc-3.2.2-win32/win64

dje

  • Full Member
  • ***
  • Posts: 134
Re: and operator
« Reply #1 on: July 02, 2022, 01:22:01 pm »
? what?
The code will call one of the two cases regardless and they both show the caption of a control.

What did you expect?

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 258
Re: and operator
« Reply #2 on: July 02, 2022, 01:23:47 pm »
To show only if caption was 'I'. Not any other.
lazarus 3.2-fpc-3.2.2-win32/win64

Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: and operator
« Reply #3 on: July 02, 2022, 01:24:59 pm »
Is this what you want
Code: Pascal  [Select][+][-]
  1. if (PanelRegexModifiers.Controls[Cnt].Caption = 'I') then
  2. begin
  3.   if (PanelRegexModifiers.Controls[Cnt] as TCheckBox).Checked then
  4.   begin
  5.     // Shows 'S' or whatever, but should be here only if it was 'I'
  6.     showmessage(PanelRegexModifiers.Controls[Cnt].Caption);
  7.   end
  8.   else
  9.   begin
  10.     //Shows 'S' or whatever, but should be here only if it was 'I'
  11.     showmessage(PanelRegexModifiers.Controls[Cnt].Caption);
  12.   end;
  13. end;
  14.  
?
« Last Edit: July 02, 2022, 01:27:04 pm by Thausand »

Paolo

  • Sr. Member
  • ****
  • Posts: 499
Re: and operator
« Reply #4 on: July 02, 2022, 01:27:34 pm »
the first branch is executed only if both conditions are true
the "else" branch is executed in all other cases (even if it is "I" and checked=false)

PS: no need to write checked = true, just checked is enough.

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 258
Re: and operator
« Reply #5 on: July 02, 2022, 01:30:03 pm »
I see it now. Damn.

Thanks to all.
lazarus 3.2-fpc-3.2.2-win32/win64

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: and operator
« Reply #6 on: July 02, 2022, 01:35:29 pm »
Code: Pascal  [Select][+][-]
  1.   if (PanelRegexModifiers.Controls[Cnt] as TCheckBox).Checked then
  2.     case PanelRegexModifiers.Controls[Cnt].Caption = 'I' of
  3.       True:  Showmessage(PanelRegexModifiers.Controls[Cnt].Caption + ' - True');  
  4.       False: Showmessage(PanelRegexModifiers.Controls[Cnt].Caption + ' - False');
  5.     end;

- Remove unnecessary begin-end pairs to make it more readable
- Consider to use case-select statement
- Something.Checked = True can be simplified (see @Paolo explanation)

alpine

  • Hero Member
  • *****
  • Posts: 1038
Re: and operator
« Reply #7 on: July 02, 2022, 01:49:29 pm »
Hmm, I'm confused...

For what is that if? Because the OP shows same message for both then and else clauses.

@Handoko
You're changing the logic, whatever it could be originally.

The source comments are confusing.
Where is the question in the original post?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: and operator
« Reply #8 on: July 02, 2022, 02:15:21 pm »
That was a guessing game. Someone provide a very short hint and you guess.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: and operator
« Reply #9 on: July 02, 2022, 02:37:03 pm »
That was a guessing game. Someone provide a very short hint and you guess.

Don't knock him: he clarified things when prodded, and said thanks when he realised the problem... which is more than a lot of people do.

However you'd expect somebody with a couple of hundred postings to his name to know better than to post something as nonsensical as his OP, which amounted to a single character.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: and operator
« Reply #10 on: July 02, 2022, 03:02:49 pm »
However you'd expect somebody with a couple of hundred postings to his name to know bette
Handoko is well over 99% correct, while I myself scored just over 95% correct. Your score is about 90% correct. We are not Sarah or Marco.  :P :o ;D Or Florian or Jonas.
Handoko took the trouble of an educated guess that looks very reasonable given the provided information.
OP is notorious for providing not enough info.  >:D
Number of posts does not matter. Only quality counts, like Handoko always tries to do.
I could have written in private, but you went way too far, so public. Period.
« Last Edit: July 02, 2022, 03:17:19 pm by Thaddy »
Specialize a type, not a var.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: and operator
« Reply #11 on: July 02, 2022, 03:45:05 pm »
After years of doing programming, I've learned these from my experience:
  • When I think a bug is hiding in certain lines, often it turns out in the location I didn't expected. That's why when someone having bug in his/her code, the first thing I want to see is the whole source code.
  • Writing well formatted-readable code can minimize bugs.
OP did post some lines. But what was the problem? Before I posted my response, OP already said he saw the problem. So, I guessed what was the bug and what solution he needed. To me, that was a guessing game for weekend. Did I wrong?

Anyway, glad to know OP got the answer for his problem.

alpine

  • Hero Member
  • *****
  • Posts: 1038
Re: and operator
« Reply #12 on: July 02, 2022, 06:42:07 pm »

However you'd expect somebody with a couple of hundred postings to his name to know bette
Handoko is well over 99% correct, while I myself scored just over 95% correct. Your score is about 90% correct. We are not Sarah or Marco.  :P :o ;D Or Florian or Jonas.
Handoko took the trouble of an educated guess that looks very reasonable given the provided information.
OP is notorious for providing not enough info.  >:D
Number of posts does not matter. Only quality counts, like Handoko always tries to do.

(Benevolently) Is there such a kind of guessing right/wrong user score?
My impression is that there are people that always (unreservedly) wants to help, Handoko being one of them. But answering with a guess, often hastily, won't it make things worse? IMO for such a bad posting the OP should be asked for clarification or just ignored.

@Handoko
With all due respect
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: and operator
« Reply #13 on: July 02, 2022, 07:06:51 pm »
I didn't post my answer hastily, I read the first post several times before I wrote it. But because I couldn't be sure mine was the correct answer so I said I was guessing.

IMO for such a bad posting the OP should be asked for clarification or just ignored.

We may feel irritated when seeing someone asking question but provide too little information. But I think differently, maybe OP isn't good in English so he chose using less words. At least his name makes me think so.

alpine

  • Hero Member
  • *****
  • Posts: 1038
Re: and operator
« Reply #14 on: July 02, 2022, 07:46:16 pm »
I didn't post my answer hastily,
I know, I've checked the timing. Even more I wrote "often hastily" meaning the usual case, not the particular one.

I read the first post several times before I wrote it. But because I couldn't be sure mine was the correct answer so I said I was guessing.
I'm in that forum for more than a 15 months, I have seen your sincere willingness to help people, once again, respect.

IMO for such a bad posting the OP should be asked for clarification or just ignored.

We may feel irritated when seeing someone asking question but provide too little information. But I think differently, maybe OP isn't good in English so he chose using less words. At least his name makes me think so.

As little as a single question mark?

As I wrote - then/else clauses are the same, from the condition it seems he wants to detect the checked 'I' option, otherwise to do ... what?
From posts of Thausand and yours, only the 'I' option is detected and then a second inner if/else. No else for the outer if,  that is - changed logic. But is that (or another) logic the intention of the OP? All branches lead to the same ShowMessage(), thus all snippets are in fact equivalent! How someone can guess anything?

Assuming the OP is a newbie, that won't help, IMO better to ask or just wait for him to find that he is posting hastily? 

Edit: No, not all snippets are equivalent because of the changed logic (when Caption<>'I'). Sorry.
« Last Edit: July 02, 2022, 07:49:40 pm by y.ivanov »
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

 

TinyPortal © 2005-2018