Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 04/20/22 in all areas

  1. Another open source Delphi project worth spreading - a pure Delphi implementation of a rich text editor, like TRichEdit, in BSD license. But be aware - although the classes/methods/vars are well named in English, the comments and documents are in Chinese. So feel free to ignore it if you mind that. https://github.com/59079096/HCView-Pascal
  2. Johansy

    Error 2597

    Error 2597 Good everyone, I have reinstalled Windows and Rad Studio Alexandria, what used to work, the build for Android at 32 and 64 bit, now does not compile, I have tried with different versions of SDK and always shows me the same error: [DCC Error] E2597 c:\program files (x86)\embarcadero\studio\22.0\lib\Android\debug\SysInit.o: error adding symbols: File in wrong format.
  3. There are a number of problems with that code: - the wScanCode parameter of ToUnicodeEx() is not optional. Unfortunately, the OnKeyUp event does not give you the original scan code that the OS provided in the WM_KEYUP message. However, in this case, since only bit 15 of the scan code is really needed, you can fake it. For a KeyUp event, bit 15 needs to be set to 1, not 0. - you are not populating the TKeyboardState before passing it in to ToUnicodeEx(). You need to call GetKeyboardState() first. - you are passing in a single WideChar for the output buffer to ToUnicodeEx(), but you are telling ToUnicodeEx() that the buffer is large enough to hold 255 WideChars, which is a lie. The output of the conversion can be more than 1 WideChar, so you need to allocate enough space to hold the entire result. The return value will tell you how many WideChars were actually written to the buffer. - ToUnicodeEx() alters the keyboard state while translating the key, unless you ask it not to (Windows 10+ only). - WideCharToString() expects a null-terminated PWideChar string, not a single WideChar. With that said, try something more like this instead: procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); var buf: array[0..15] of WideChar; KSta: TKeyboardState; numChars: Integer; begin Winapi.Windows.GetKeyboardState(ksta); numChars := Winapi.Windows.ToUnicodeEx(key, $8000, ksta, buf, Length(buf)-1, 4, 0); if numChars > 0 then begin buf[numChars] := #0; log.Lines.Add('KeyUp : ' + IntToStr(Key) + ' = ' + WideCharToString(buf)); end else if numChars = 0 then log.Lines.Add('KeyUp : ' + IntToStr(Key) + ' = (no translation)') end else log.Lines.Add('KeyUp : ' + IntToStr(Key) + ' = (dead key)'); end; However, if you really want to handle individual key presses, you should be using the OnKeyPress event of the OnKey[Down|Up] events, as previously stated. The OnKeyPress event gives you translated Unicode characters, not virtual key codes. procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); begin log.Lines.Add('KeyPress : ' + IntToStr(Key) + ' = ' + Key); end;
  4. buf is declared as a single Widechar but you tell ToUnicodeEx that it can hold 255 Widechars. A good way to ruin your call stack.
  5. The lack of an Enumeration constraint is one of my big annoyances with Delphi Generics. No support for ord, pred, succ, or set of, in, or other set operators.
×