문제

This is my code:

**if** FWordApp = UnAssigned **then**
    FWordApp := CreateOleObject('Word.Application') ;
Result := FWordApp;

The above sits in a GETter for a property of type OleVariant.

The first time, it goes through fine, compares TRUE to Unassigned. However, the same isn't true the second time, where comparing to UnAssigned gives me an Invalid Variant Operation error.

도움이 되었습니까?

해결책

As the error message is telling you, you are not allowed to compare Unassigned against a COM object in the context of an OleVariant. That's an illegal comparison.

Your test should instead use VarIsEmpty:

if VarIsEmpty(FWordApp) then
  FWordApp := CreateOleObject('Word.Application');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top