Unicode in Delphi form TRectangle TText

假如想象 提交于 2019-12-07 08:45:53

问题


I'm new to Delphi & in DelphiXE4 editor I am trying to make chessboard gui on form, using x64 TRectangle for board (alternate colors). I want to add unicode chess pieces but in ObjectInspector properties when I add unicode it displays literally on the form. How can I add Unicode to TText (so the form displays unicode as chess pieces)? (After I want to add dragndrop to TRectangles/unicode chess-any ideas?).

Rectangle63: TRectangle;
Rectangle64: TRectangle;
Text1: TText;
Text2: TText;

Here is screenshot showing problem:

I'm most grateful for help, thanks

EDIT: Jeroen's answer worked to solve this for me (which I did by copy/paste the actual unicode chess piece image into TText text property). I add screenshot of exe so far. Next up I want to add DRAGNDROP to these pieces.....

EDIT2: (Jeroen-font size issue fixed) Fixed unicode black king display-see screenshot:


回答1:


The Unicode Chess Pieces can be shown in any Delphi application provided you have a fond that contains the Glyphs for the various CodePoints in Unicode representing the Chess Pieces.

Actually, it does not matter what platform or development environment you use, as long as they support Unicode and you have the right font.

You need:

  1. a means to enter these Unicode CodePoints
  2. a font representing these Unicode CodePoints as Glyphs on your target platform

To start with the last, for Microsoft Windows, these fonts work fine:

  • Segoe UI
  • Tahoma
  • Arial Unicode MS

For entering these there are two approaches on Microsoft Windows:

  1. if you enable it in the registry: enter hexadecimal Unicode CodePoint numbers through Alt-codes on the keyboard
  2. copy/paste them from an application (i.e. Unicode Input: Selection from Screen) that provides them as text

For copy/paste, I often go to a web page with the correct characters using a Web Browser that supports Unicode, or search for them using the Character Map application.

To make copy/paste easier:

  • These are the white pieces: ♔♕♖♗♘♙
  • These are the black pieces: ♚♛♜♝♞♟

Example FireMonkey form with all the pieces in 1 TText in one TTRectangle:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 480
  ClientWidth = 640
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [dkDesktop, dkiPhone, dkiPad]
  DesignerMobile = False
  DesignerWidth = 0
  DesignerHeight = 0
  DesignerDeviceName = ''
  DesignerOrientation = 0
  object Rectangle1: TRectangle
    Height = 50.000000000000000000
    Width = 80.000000000000000000
    object Text1: TText
      Color = claBlack
      Height = 50.000000000000000000
      Text = #9812#9813#9814#9815#9816#9817#9818#9819#9820#9821#9822#9823
      Width = 80.000000000000000000
    end
  end
end

Edit

I think you have a font size issue in your form file. Create a new question with the text of your form file. Two ways to do that:

  1. open Notepad, and in notepad open the .FMX file that goes with your form; copy the text to the clipboard
  2. In Delphi, right click on the form then choose "View as Text", select all the text and copy it to the clipboard, right click on your form text then select "View as Form".

Paste the code at http://pastebin.com/ or https://gist.github.com/ then post that link in a new question. After that comment here you did and I will take a look.



来源:https://stackoverflow.com/questions/17189143/unicode-in-delphi-form-trectangle-ttext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!