Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > win32com and com Record types

Reply
Thread Tools

win32com and com Record types

 
 
Mike Margerum
Guest
Posts: n/a
 
      08-19-2003
Hi I am trying to using a COM server I built in C++. I ran GenPy on
my type library and I am able to instantiate objects from the server.
What I can't figure out is how to create/use Record types from my COM
server. I see them defined in my generated py file as a map

RecordMap = {
'FormRecord': '{F6EBBC2A-E2D5-4921-A498-EA80AE851012}',
'ICD9Record': '{FA83723F-55F6-4D17-8309-A9D323A4FD01}',
'BrandRecord': '{AD4B5647-E78A-447B-A041-EEC59E89D3F6}',
}

How Do i instantiate one so I can use it in one of my methods that
takes a BrandRecord by reference?

This is a snippet of VB code that works

Dim db As New BrandDb
db.Open ("c:\temp\irx2_brand.pdb")
Dim brandRec As BrandRecord
While i < db.RecordCount
db.GetBrand i, brandRec, 1 'use 0 instead of 1 to not load
form data
List1.AddItem brandRec.MasterIndex & " " & brandRec.Id & " " &
brandRec.Description

This is my python code that is working minus the GetBrand call

from win32com.client import *
from PDBUtils import *
db = BrandDb()
print db.Version
db.Open(r"c:\temp\irx2_brand.pdb")
for i in range(0,db.RecordCount):
print i

Thanks a lot for the help.
 
Reply With Quote
 
 
 
 
Mark Hammond
Guest
Posts: n/a
 
      08-19-2003
Mike Margerum wrote:
> Hi I am trying to using a COM server I built in C++. I ran GenPy on
> my type library and I am able to instantiate objects from the server.
> What I can't figure out is how to create/use Record types from my COM
> server. I see them defined in my generated py file as a map
>
> RecordMap = {
> 'FormRecord': '{F6EBBC2A-E2D5-4921-A498-EA80AE851012}',
> 'ICD9Record': '{FA83723F-55F6-4D17-8309-A9D323A4FD01}',
> 'BrandRecord': '{AD4B5647-E78A-447B-A041-EEC59E89D3F6}',
> }
>
> How Do i instantiate one so I can use it in one of my methods that
> takes a BrandRecord by reference?
>
> This is a snippet of VB code that works
>
> Dim db As New BrandDb
> db.Open ("c:\temp\irx2_brand.pdb")
> Dim brandRec As BrandRecord
> While i < db.RecordCount
> db.GetBrand i, brandRec, 1 'use 0 instead of 1 to not load
> form data
> List1.AddItem brandRec.MasterIndex & " " & brandRec.Id & " " &
> brandRec.Description


You can create a record object by using:

r = win32com.client.Record("RecordName", object)

where "RecordName" is the name of the record, and 'object' is &any* COM
object defined in the same type library.

See win32com\test\testvb for some real examples.

Mark.

 
Reply With Quote
 
 
 
 
Chuck Spears
Guest
Posts: n/a
 
      08-20-2003
When I run this code, it fails on the line where i try to create a
record. Thanks again for the help.

import win32com.client
db=win32com.client.Dispatch("PDBUtils.BrandDb")
db.Open (r"c:\temp\irx2_brand.pdb")
for i in range(0,db.RecordCount):
print i
rec = win32com.client.Record("BrandRecord", db)


0
Traceback (most recent call last):
File "c:\temp\test\comTest.py", line 18, in ?
rec = win32com.client.Record("BrandRecord", db)
File "C:\PYTHON22\lib\site-packages\win32com\client\__init__.py",
line 392, in Record
object = gencache.EnsureDispatch(object)
File "C:\PYTHON22\lib\site-packages\win32com\client\gencache.py",
line 442, in EnsureDispatch
raise TypeError, "This COM object can not automate the makepy
process - please run makepy manually for this object"
TypeError: This COM object can not automate the makepy process -
please run makepy manually for this object

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Argument type of function and safe types and types, arguments canhandle safely ittium C++ 4 12-09-2011 11:05 AM
IP Address, MX Record, A Record Question K.J. 44 Cisco 2 09-06-2006 05:14 PM
You cannot add or change a record because a related record is required in table 'lok" André ASP .Net 0 06-25-2006 01:30 PM
Retrieving Record Key while creating the record. =?Utf-8?B?SnVzdGlu?= ASP .Net 4 10-05-2004 08:11 PM
" Invalid Disk Table in Boot Record - Boot Record could not be repaired " reply@newsgroup.please Computer Support 2 12-01-2003 05:37 AM



Advertisments