변환 DevExpress TcxFilterOperatorKind string?
-
05-07-2019 - |
문제
여기에 codesnippet 사용 filtertype 운전자에게 필터에서 DevExpress 그리드:OperatorKindToStr 사용하여 추출물 operatorkind 에서는 필터로 문자열에 저장 xml 파일입니다.StrToOperatorKind 로 변환하는 데 사용되는 다시 문자열에서는 xml 을 설정 operatorkind 에서는 필터입니다.
const
CUSTFILTER_FILTERITEM = 'FilterItem';
function OperatorKindToStr(const aOperatorKind: TcxFilterOperatorKind): string;
begin
Result := 'foEqual';
case aOperatorKind of
foEqual: Result := 'foEqual';
foNotEqual: Result := 'foNotEqual';
foLess: Result := 'foLess';
foLessEqual: Result := 'foLessEqual';
// Plus a boring list of other constants
end;
function StrToOperatorKind(const aOpKindStr: string): TcxFilterOperatorKind;
begin
Result := foEqual;
if aOpKindStr = 'foNotEqual' then
Result := foNotEqual
else if aOpKindStr = 'foLess' then
Result := foLess
else if aOpKindStr = 'foLessEqual' then
Result := foLessEqual
else if aOpKindStr = 'foGreater' then
Result := foGreater
else if aOpKindStr = 'foGreaterEqual' then
Result := foGreaterEqual
// Plus a boring list of other if-else
end;
procedure UseStrToOperatorKind(const aFilterItem: IXmlDomElement);
begin
if aFilterItem.nodeName = CUSTFILTER_FILTERITEM then
begin // It is an FilterItem
vStr := VarToStr(aFilterItem.getAttribute(CUSTFILTER_COLPROP)); // Get the columnname
vOperatorKind := StrToOperatorKind(aFilterItem.getAttribute(CUSTFILTER_ITEMOPERATOR));
end;
procedure UseOperatorKindToStr(const aFilterItem: TcxCustomFilterCriteriaItem);
var
vStr: String;
begin
if Supports(TcxFilterCriteriaItem(aFilterItem).ItemLink, TcxGridColumn, GridCol) then
vStr := OperatorKindToStr(TcxFilterCriteriaItem(aFilterItem).OperatorKind);
end;
분명히 내가 원하는 StrToOperatorKind 및 OperatorKindToStr 조금 똑똑합니다.가 GetEnumProp 방법에 VCL 않음이지만 그것은 작동하지 않습니다.그래서 어떻게 추출할 수 있는 TcxFilterOperatorKind 시설에서 aFilterItem 변수 문자열을 TcxFilterOperatorKind?
해결책
사 GetEnumName 고 GetEnumValue 듀엣으로 메이슨이 지적했다.
과 함수해야 되는 훨씬 더 간단하다:
function OperatorKindToStr(const aOperatorKind: TcxFilterOperatorKind): string;
begin
Result := GetEnumName(TypeInfo(TcxFilterOperatorKind), Ord(aOperatorKind));
end;
function StrToOperatorKind(const aOpKindStr: string): TcxFilterOperatorKind;
begin
Result := TcxFilterOperatorKind(GetEnumValue(TypeInfo(TcxFilterOperatorKind), aOpKindStr));
end;
다른 팁
GetEnumProp 작동하지 않았기 때문에 그것이 잘못된 기능을 위해 당신이 무엇을 행하려고 노력하는 것입니다.당신은 가까이도.Try GetEnumName 및 GetEnumValue 도에 TypInfo 단위입니다.
제휴하지 않습니다 StackOverflow