Problem: 1115111
Title: (2-BYTE) TTEView::GetNumberOfChars returns 0 after 1 character has been typed
Received: Sep 24 1993 5:22PM
To demonstrate this define a subclass of TTEView with a method DoEvent.
In your subclassed method DoEvent make the first two lines:
TTEView :: DoKeyEvent(event); /* make sure the normal MacApp processing is done */ int theTELength = this->GetNumberOfChars(); /* measure the length */
Instantiate the view using (say) ViewEdit and a call to NewtemplateWindow in your test program.
Set a breakpoint on the second statement. Let the application run. Type a character into the view. It should stop at the breakpoint.
Use Sourcebug or writeln to evaluate theTELength.
If the TEView is intially empty, the length will be zero (one less than it should be) after the first key down event. After the second it will be 2 (OK) and after the third 3 (OK) and so on.
If the TEView has n characters, the length will be n (one less than it should be) after the first key down event. After the second it will be n+2 (OK) and after the third n+3 (OK) and so on.
We discovered this because we do an Oracle database search as each character is typed.
Looking at hte->teLength instead of GetNumberOfChars() gives the same results.
The result of GetNumberOfChars() is not correct at first charpressed because, I think, TTEView::fTypingCommand is NULL. We do not call fTypingCommand->AddCharacter(text) immediately instead of calling PostCommand(), that means fTypingCommand->AddCharacter() will be called at next command loop. The code in TTEView::DoKeyEvent:
needNewCommand = (fTypingCommand == NULL) .... if (needNewCommand) { ... PostCommand(aTypingCommand); // WILL NOT ADD CHAR RIGHT NOW } else { ... fTypingCommand->AddCharacter(text); ... }
The possible solutions:
1) Don't call GetNumberOfChars() inside DoKeyEvent() of sub-class.
2) Modify code to call fTypingCommand->AddCharacter(text) sooner.
Moved the AddCharacter call (that adds the first character typed) to the TTETypingCommand constructor from DoIt.