N
N
Nekit Medvedev2017-06-08 08:18:41
Delphi
Nekit Medvedev, 2017-06-08 08:18:41

How to equate a string variable to a property value?

code
text:=RichEdit1.SelAttributes.Style;
output error:
[dcc32 Error] Unit4.pas(124): E2010 Incompatible types: 'string' and 'TFontStyles'
how to fix?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
n-fom, 2017-06-08
@NIKROTOS

uses System.TypInfo;

type TEnumConverter = class
public
  class function EnumToInt<T>(const EnumValue: T): Integer;
  class function EnumToString<T>(EnumValue: T): string;
  class function GetAs<T>(pValor: String): T;
end;

implementation

class function TEnumConverter.EnumToInt<T>(const EnumValue: T): Integer;
begin
  Result := 0;
  Move(EnumValue, Result, sizeOf(EnumValue));
end;

class function TEnumConverter.EnumToString<T>(EnumValue: T): string;
begin
  Result := GetEnumName(TypeInfo(T), EnumToInt(EnumValue));
end;

class function TEnumConverter.GetAs<T>(pValor: String): T;
var
  Tipo: PTypeInfo;
  Temp: Integer;
  PTemp: Pointer;
begin
   Tipo := TypeInfo(T);
   Temp := GetEnumValue(Tipo, pValor);
   PTemp := @Temp;
   Result := T(PTemp^);
end;

A
Alexander Skusnov, 2017-06-08
@AlexSku

Style is a set of enums. This type is not compatible with string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question