Im trying to make it so once different text is entered the shape will change color but it says theres a problem with ('A .. 'Z') being 'Expected ) but received a string literal ''A'' '. and im not sure how to fix it. Any help appreciated, thanks!

type
  TCapitalLetter = ('A' .. 'Z' ); //subrange of type char
  TDigit = ('0' .. '9' ); //subrage of type char
有帮助吗?

解决方案

Your definition is close, but it's not quite right:

type
  TCapitalLetter = 'A'..'Z';
  TDigit = '0'..9';

From your other question, though, I don't think that's what you really need to do. You're looking for membership (some character being contained in that type), in which case you need to do it using sets. It's a console application you can just compile and test:

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  TCapitalLetters = TSysCharSet; 
  TDigits = TSysCharSet;

const
  CapitalLetters: TCapitalLetters = ['A'..'Z'];
  Digits: TDigits = ['0'..'9'];

var
  Temp, Output: string;
  Ch: Char;

begin
  Output := '';
  Temp := 'Seems A Nice Test Answer';
  for Ch in Temp do
    if CharInSet(Ch, CapitalLetters) then
      Output := Output + Ch;

  WriteLn(Output);
  ReadLn;
end.

For earlier (non-Unicode) versions of Delphi, you need to use set of Char instead of TSysCharSet, and use a slightly different syntax for the set membership:

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  TCapitalLetters = set of Char;
  TDigits = set of Char;

const
  CapitalLetters: TCapitalLetters = ['A'..'Z'];
  Digits: TDigits = ['0'..'9'];

var
  Temp, Output: string;
  Ch: Char;

begin
  Output := '';
  Temp := 'Seems A Nice Test Answer';
  for Ch in Temp do
    if Ch in CapitalLetters then
      Output := Output + Ch;

  WriteLn(Output);
  ReadLn;
end.

Output of test app:

Screen capture of test app output

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top