2012-07-03 2 views
1

ABBYY Flexicapture에서 일부 스크립트를 C# .NET으로 작성하도록하고 있습니다. C# .NET은 사용하지 않지만 필자가 사용하는 Java에 충분히 근접합니다. 나는 다음과 같은 표시하는 method 선언이 있습니다메소드 정의에서 VARIANT라는 용어는 무엇을 의미합니까?

그래서
Document: 
    Property (name: string) : VARIANT 
     Description: Retrieves the value of a specified property by its name. The returned value can be in the form of a string, a number or time. 
     Properties names and returned values: 
      Exported - when the document was exported 
      ExportedBy - who exported the document 
      Created - when the document was created 
      CreatedBy - who created the document 

나는 값이 "내 보낸"얻으려고하지만 다음 줄을 중 하나를하려고 할 때 오류 얻을 :

string = Document.Property("CreatedBy"); // Returns Error: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?) (line 95, pos 21) 
string = Document.Property(CreatedBy); // Returns Error: Error: The name 'CreatedBy' does not exist in the current context (line 95, pos 39) 
string = Document.Property("CreatedBy").Text; //Error: 'object' does not contain a definition for 'Text' (line 95, pos 52 

나는 전에 VARIANT이 사용 된 것을 본 적이 없지만 누군가이 설명을 해줄 수 있습니까? 임 누락 된 구문 오류가 있습니까?

+1

개체 s = Document.Property ("CreatedBy") ;? – Vlad

+2

string = Document.Property ("CreatedBy"); // Returns Error : 암시 적으로 'object'유형을 'string'으로 변환 할 수 없습니다. 이 오류 메시지는 Document.Property ("CreatedBy")가 개체임을 나타냅니다. – sgmoore

+0

@Vlad - 고마워, 그게 다야. 그럼 내가'.ToString()'을 변환하고 모든 것이 잘 작동했다. – ProfessionalAmateur

답변

1

변형은 실제로 다른 유형의 "합집합"입니다.

if (o is string) 
{ 
    string s = (string)o; 
    // work with string s 
} 
else if (o is int) 
{ 
    int i = (int)o; 
    // work with int i 
} 
// etc. for all possible actual types 

또는, 당신이 문자열 표현 (o.ToString())에 개체를 변환과 함께 작업 할 수 있습니다이 표현하는 좋은 방법은

object o = Document.Property("CreatedBy"); 

이제 o의 정확한 유형을 확인하실 수 있습니다.

2

저는 ABBYY Flexicapture에 익숙하지 않지만 COM을 다시 사용 했으므로 VARIANT를 많이 사용했습니다. 기본적으로 문자열, 숫자 또는 날짜가 될 수있는 값 유형입니다.

이것은 당신이 인용 한 선언에 주어진 설명과 함께 줄을 보인다

The returned value can be in the form of a string, a number or time.

변형 자바 스크립트와 같은 약하게 입력 (스크립트) 언어에서 변수와 유사하다.

자세한 내용은 Wikipedia을 확인하십시오.

관련 문제