In the COM API I am using, the following is provided: To
create a new patient object I have to cast the Patient
manager interface to the IDIContstructor interface.
PatMgr: IDIPatientMgr;
NewPat: IDIPatient;
...
PatMgr := DISession.GetManagerById(miPatient) as
IDIPatientMgr;
NewPat := (PatMgr as IDIConstructor).CreateNew as
IDIPatient;
//edit the patient...
//Save the changes
(NewPat as IDIEdit).Save;
In python I have written the following code.
miPerson = 26
try:
PersonMgr
except NameError:
PersonMgr = self.__dips_api.GetManagerById(miPerson)
else:
print "PersonMgr eksisterer"
NewPerson = CastTo(PersonMgr, 'IDIPersonMgr')
This casts PersonMgr to the right Interface.
My problem is that once I use the CastTo function all of
my other functions cease to work. Apparently all the
objects are wrapped in PyIUnkown, and python is no
longer able to find their appropriate type. This problem
will persist until delete the automatically generated
python COM code and restart IDLE.
All the interfaces I am using are IDispatch.
I have also tried to alternatively cast the interface with
PersonMgr.QueryObject(IDIConstructor) and
Dispatch(PersonMgr , None, 'IDIContructor'),
but these functions are unable to find the interface.
Have also tried with makepy
Can anyone provide information on how to make CastTo
work, (can I unwrap the PyIUnknown wrapper?)
Ole A
Logged In: YES
user_id=1216110
The line
NewPerson = CastTo(PersonMgr, 'IDIPersonMgr')
is
NewPerson = CastTo(PersonMgr, 'IDIConstructor')
and IDIContructor should be IDIConstructor
This however is not the problem
Ole A
Logged In: YES
user_id=1216110
The following code corrects the problem in a similar function,
but it does not help with the CreateNew function:
Patient = PatientMgr.GetPatientById
('aakajf+0000005001392')
Person = Dispatch(Patient, 'IDIPerson', '{F6C0D843-
DEC8-4C31-A766-12CBE59F3184}', UnicodeToString=0)
Person = Person._oleobj_.QueryInterface
(pythoncom.IID_IDispatch)
Person = Dispatch(Person)
print Person.LastName
Logged In: YES
user_id=1216110
The COM objects are written in Delphi
Logged In: YES
user_id=14198
You indicate you get back an IUnknown - can you call
QueryInterface on this IUnknown for IDispatch?
Logged In: YES
user_id=14198
are you still having this problem?
Logged In: YES
user_id=1216110
I sill have the problem (but I have been on a two week
vacation, so I haven't been working on it...). I seem to be able
to get the right Interface, but get the following error when I try
CreateNew():
line 327, in CreateNew
ret = self._oleobj_.InvokeTypes(1, LCID, 1, (13, 0), (),)
com_error: (-2147352562, 'Ugyldig antall parametere.(Invalid
number of parameters)', None, None)