Answer the question
In order to leave comments, you need to log in
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
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;
Style is a set of enums. This type is not compatible with string.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question