Rowset?

You are familiar with this block:

Var
  mySet: Set Of Char;
  C: Char;
begin
  mySet := ['a', 'b', 'c'];
  If C In mySet Then ShowMessage('Exists');
end;

Is there any way to declare Set Of STRING? or is there similar code that i can use instead? An important part of this block is If C In mySet Then ShowMessage('Exists');I want to use something like this in a rowset.
Thank.

+6
source share
5 answers

You can use this.

type 
  TAnyEnum = (aeVal1, aeVal2, aeVal3);
  TEnuns = set of TAnyEnum;
  TAnyMessages: array [TAnyEnum] of String;

const 
  MyMessages: TAnyMessages = ('Exists', 'Something else', 'WTF!?');

var
  MySet : TEnums;
begin
  MySet = [aeVal1, aeVal2];
  If aeVal1 in MySet then ShowMessage(MyMessages[aeVal1]);
end;
+8
source

Sets are implemented using bit arrays. So no, you cannot have a "rowset". Use a TStringList instead, i.e.:

var 
  mySet: TStringList;
  S: String;
begin 
  S := ...;
  mySet := TStringList.Create;
  try
    mySet.Add('a');
    mySet.Add('b');
    mySet.Add('c'); 
    if mySet.IndexOf(S) <> -1 Then ShowMessage('Exists');
  finally
    mySet.Free;
  end;
end; 
+11
source

, Delphi , . "Fabricio Araujo" - , , - . 256 " ". TStringList , , . Delphi TDictionary , :

procedure TForm6.FormCreate(Sender: TObject);
type
  TEmpty = record end;
var
  MySet: TDictionary<String, TEmpty>;
  Dummy: TEmpty;
begin
  MySet := TDictionary<String, TEmpty>.Create;
  try
    MySet.Add('Str1', Dummy);
    MySet.Add('Str2', Dummy);
    MySet.Add('Str3', Dummy);
    if MySet.TryGetValue('Str2', Dummy) then
      ShowMessage('Exists');;
  finally
    MySet.Free;
  end;
end;

. , , /, ( AnsiLowerCase).

+3

"" , string array of string.

String.Join() Array of string , , Contains() .

"" , array of string :

  1. .

( / ):

var
  sEvaluate: string;
  sLanguages: string;
const
  cLanguages: array[0..5] of string = ('fr-FR', 'en-GB', 'de-DE', 'it-IT', 'fr-CH', 'es-ES');
begin
  try
    { TODO -oUser -cConsole Main : Insert code here }
    while True do
    begin
      Write('type the text to evaluate (e for exit): ');
      Readln(sEvaluate);
      if SameText(sEvaluate, 'e') then
        break;
      sLanguages := String.Join('|', cLanguages) + '|'; // use a special char as a separator
      if sLanguages.Contains(sEvaluate + '|') then
        Writeln('found')
      else
        Writeln('not found');
    end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

, String.Join() array of const array of const , :

sLanguages := String.Join('|', ['fr-FR', 'en-GB', 'de-DE', 'it-IT', 'fr-CH', 'es-ES']) + '|';
if sLanguages.Contains(sEvaluate + '|') then
  Writeln('found')
...
+1

RTL System.StrUtils :

function MatchText(const AText: string; const AValues: array of string): Boolean; overload;

:

  if MatchText(sLanguages, ['fr-FR', 'en-GB', 'de-DE', 'it-IT', 'fr-CH', 'es-ES']) then
    Writeln('found')
0

All Articles