Recent

Author Topic: [Solved]error release when memo.setfocus  (Read 922 times)

badmintonfan

  • New Member
  • *
  • Posts: 32
[Solved]error release when memo.setfocus
« on: January 26, 2023, 05:42:08 am »
What's wrong on my code?
« Last Edit: February 06, 2023, 04:36:56 am by badmintonfan »

dseligo

  • Hero Member
  • *****
  • Posts: 953
Re: error release when memo.setfocus
« Reply #1 on: January 26, 2023, 06:34:39 am »
What's wrong on my code?

You can't focus controls in OnCreate event. Put your code in OnShow event.

badmintonfan

  • New Member
  • *
  • Posts: 32
Re: error release when memo.setfocus
« Reply #2 on: January 26, 2023, 10:38:36 am »
What's wrong on my code?

You can't focus controls in OnCreate event. Put your code in OnShow event.
I did it alreay,but the same error message had been released

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1187
  • Fifty shades of code.
    • Delphi & FreePascal
Re: error release when memo.setfocus
« Reply #3 on: January 26, 2023, 11:22:07 am »
Never ever explicit check for "True" or "False". That is really bad code up there.
Code: Pascal  [Select][+][-]
  1. if (not Edit1.Enabled) then Memo1.SetFocus;
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

dseligo

  • Hero Member
  • *****
  • Posts: 953
Re: error release when memo.setfocus
« Reply #4 on: January 26, 2023, 10:36:24 pm »
What's wrong on my code?

You can't focus controls in OnCreate event. Put your code in OnShow event.
I did it alreay,but the same error message had been released

It doesn't look like you did that in your original post. You try to focus Memo1 in method named FormCreate, which is default when you double click on form or if you click on OnCreate event in object inspector.

I think you didn't do put your code in OnShow event properly. I mean: if you get this error, then focusing in OnCreate is still happening.

I suggest you make small project that shows this behaviour and post it here.

VTwin

  • Hero Member
  • *****
  • Posts: 1182
  • Former Turbo Pascal 3 user
Re: error release when memo.setfocus
« Reply #5 on: January 27, 2023, 12:59:28 am »
It is almost impossible to help if you do not post the project or code.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.4 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.4 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.4 (64 bit on VBox)

badmintonfan

  • New Member
  • *
  • Posts: 32
Re: error release when memo.setfocus
« Reply #6 on: January 27, 2023, 05:36:04 am »
It is almost impossible to help if you do not post the project or code.
Please look at it

dseligo

  • Hero Member
  • *****
  • Posts: 953
Re: error release when memo.setfocus
« Reply #7 on: January 27, 2023, 05:40:29 am »
It is almost impossible to help if you do not post the project or code.
Please look at it

I suggest to you again: make small project that shows this behaviour and post it here.
If you don't want to, you could check in object inspector that OnCreate event points to FormCreate method and not to FormShow method.
Everything else is pure guessing from our side.

badmintonfan

  • New Member
  • *
  • Posts: 32
Re: error release when memo.setfocus
« Reply #8 on: February 06, 2023, 04:36:08 am »
It is almost impossible to help if you do not post the project or code.
Please look at it

I suggest to you again: make small project that shows this behaviour and post it here.
If you don't want to, you could check in object inspector that OnCreate event points to FormCreate method and not to FormShow method.
Everything else is pure guessing from our side.
I finally found the issue,it's my mistake,thanks a lot!

 

TinyPortal © 2005-2018