2015-01-14 1 views
-1

속성 설정자에서 Variant으로 선언 된 클래스 필드 변수에 UnicodeString (또는 Widestring, 시도했습니다) 값을 할당하려고합니다. 내가 System.Variants을 포함 한 interfaceuses 절에서Delphi XE5에서 Variant 변수에 문자열을 할당 할 수 없습니까?

EVariantBadVarTypeError - 'Invalid variant type' 

: 나는 오류를 받고 있어요.

가 여기에 Variant 필드 변수의 내 선언입니다 :

// Items is a TObjectList descendant 
// each item in items is an instance of TInnerClass 
TInnerClass(Items[Index]).AsString := StringList[Index]; 
// at runtime value is for ex. 'Dr.' - this assignment raises the above referenced exception 
: 여기
procedure TContainerClass.TInnerClass.SetAsString(const AValue: UnicodeString); 
begin 
    FValue := AValue; 
end; 

이 속성을 사용하는 예입니다

여기 implementation 섹션에서
TContainerClass = class(TObject) 
strict private 
... 
type 
    ... 
    TInnerClass = class 
    strict private 
    ... 
    FValue: Variant; 
    function GetAsString: UnicodeString; 
    ... 
    procedure SetAsString(const Value: UnicodeString); 
    public 
    ... 
    property AsString: UnicodeString read GetAsString write SetAsString; 
    ... 
    end; 
    ... 
end; 

내 속성 setter입니다

코드를 진행하면서 모든 객체는 제정되었다. 과제의 양면이 유효한 것으로 보입니다. 내가 부족 간단

아마
(Unknown type: 39852, (nil,$3A83700), Variant array of Unknown, $1, $F, '') 

뭔가 : 단계별 때 눈치 유일한 것은 내가 TInnerClass(Items[Index])을 평가할 때이를 볼 수 있다는 것입니다.

+0

유효한 개체 인스턴스가 있습니까? –

답변

1

(Unknown type: 39852, (nil,$3A83700), Variant array of Unknown, $1, $F, '')

변형 된 개체가 프로그램에서 손상된 것 같습니다. 코드를 식별하고 손상을 피하면 코드가 작동하기 시작해야합니다.

원시 메모리 액세스를 수행하는 코드를 찾으십시오. 예를 들어 Move에 대한 호출은 일반적인 손상 소스입니다. 마찬가지로 부실 포인터 나 참조를 사용합니다.

+0

사용하지 않음 여기를 클릭하면 부실 참조 일 가능성이 높아집니다. 그것을 추적하려고 시도 중 ... – DeCoder

관련 문제