如何声明常量Tpoint?

问题描述 投票:0回答:2

早上好, 我试图在 Delphi 中声明常量 TPoint,你如何做到这一点?

以下均无效

// ...
const POS_A : Tpoint = (3,3);  
const POS_B : Tpoint = Point(3,10);
const POS_C : Tpoint = Tpoint(3,20);
const POS_D : Tpoint = TPoint.create(3,30);
// ...

有什么线索吗?

delphi constants point
2个回答
4
投票

根据常量的文档,特别是关于记录的部分,你写

const
  MyPoint: TPoint = (X: 3; Y: 7);

0
投票
I know this post ist some years old, but my problem seems to fit here very well.
I create an array of my record type with const points but this does not work. 

I know i could simply use x and y integers directly in my record but i want 
to understand why this does not work technically.

Here is my code:

    type
      TEnumSubDirSuffix = (
        SDS_16x16,
        SDS_24x24,
        SDS_32x32,
        SDS_48x48,
        SDS_64x64
      );

      TRecImageSubDir = record
        Name : string;
        Size : TPoint;
      end;
    
    const
      Pt16: TPoint = (X: 16; Y: 16);
      Pt24: TPoint = (X: 24; Y: 24);
      Pt32: TPoint = (X: 32; Y: 32);
      Pt48: TPoint = (X: 48; Y: 48);
      Pt64: TPoint = (X: 64; Y: 64);
    
      ARR_IMAGE_SUB_DIRS: array[TEnumSubDirSuffix] of TRecImageSubDir = (
        (Name: '16x16'; Size: Pt16), // why is Pt16 and below is not accepted here?
        (Name: '24x24'; Size: Pt24),
        (Name: '32x32'; Size: Pt32),
        (Name: '48x48'; Size: Pt48),
        (Name: '64x64'; Size: Pt64)
      );
© www.soinside.com 2019 - 2024. All rights reserved.