How to use GetSetProp and SetSetProp from TypInfo module

I have a set of enumeration values ​​that I need to convert to text, and then return to the set.

I believe that GetSetProp and SetSetProp from the TypInfo module will allow this, but I don’t know how to make it work. Any idea on how I can use GetSetProp and SetSetProp for this?

type
  TSomething = (sOne, sTwo, sThree, sFour, s Five);
  TSomethings = set of TSomething;

var
  Something: TSomethings;
  s: string;
...
  Something := [sOne, sThree];

  s := GetSetProp(????);

  Something := [];
  // then use SetSetProp to set Something back to [sOne, sThree]
  Something := ????
+1
source share
2 answers

As the method name may indicate: this only works for published properties!

type
  TSomething = (sOne, sTwo, sThree, sFour, sFive);
  TSomethings = set of TSomething;
  TSomeClass = class
  private
    FSomeThing: TSomethings;
  public
  published
    property SomeThing: TSomethings read FSomeThing write FSomeThing;
  end;

...
var
  SomeClass: TSomeClass;
  s: string;
begin
  SomeClass := TSomeClass.Create;
  try
    SomeClass.Something := [sOne, sThree];
    s := GetSetProp(SomeClass, 'Something');
    ...
  finally
    SomeClass.Free;
  end;
+2
source

Source: https://habr.com/ru/post/1729705/


All Articles