BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Excel Automation

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (ActiveX)
View previous topic :: View next topic  
Author Message
William Westbrooks
Guest





PostPosted: Mon Jun 23, 2003 11:12 pm    Post subject: Excel Automation Reply with quote



Hi

Can any one tell me why I am getting an error that says a memory adderes
must be taken, which is being caused by the function
(TVariant)ExcelSheet->Cells->get_Item((TVariant)DataRow,(TVariant)(DataCol-1
)). When ever I comment this function out the error goes away or if I
compile the project in debug mode the function doesn't cause an error at
all. Only in release mode does the error occur. The cursor haults at the end
of the TDMWExcelForm4 function which get_Item is being called from when this
compiler error occurs, but it is caused by
(TVariant)ExcelSheet->Cells->get_Item((TVariant)DataRow,(TVariant)(DataCol-1
)). My code is written below.

void __fastcall TDMWExcelForm4::tsGrid1CellLoaded(TObject *Sender,int
DataCol, int DataRow, Variant &Value) {

//If this is the first column then fill in the row numbers else retrieve
the excel file values.
if(DataCol == 1) {
CellWidth = tsGrid1->Canvas->TextWidth(IntToStr(DataRow));
if(tsGrid1->Col[1]->Width < CellWidth) {
tsGrid1->Col[1]->Width = CellWidth;
}
Value = IntToStr(DataRow);
} else {

try {
CellValue =
(TVariant)ExcelSheet->Cells->get_Item((TVariant)DataRow,(TVariant)(DataCol-1
));

// If this is not an empty string
if(strcmp(CellValue.c_str(),"")!=0) {

// Make sure the column width is large enough for the data
CellWidth = tsGrid1->Canvas->TextWidth(CellValue);
if(tsGrid1->Col[DataCol]->Width < CellWidth+5) {
tsGrid1->Col[DataCol]->Width = CellWidth+10;
}

// Place the data in the table
Value = CellValue;
}
} catch(...) {
// Catch any errors getting excel values
Value = "";
}
}
}


Back to top
Pete Fraser
Guest





PostPosted: Sat Feb 04, 2006 4:01 pm    Post subject: Re: Getting menus from Explorer plugin (TortoiseCVS) Reply with quote



Thanks Remy,
That's a lot of code to get my teeth into.
The reason for all of this work is that I'm using
VirtualShellListViewEx from mustangpeek.net
which has support for context menus for files/folders
but not for the background menu - i.e. nothing
selected. So I created a basic menu that did the
normal background menu items - view-sortorder etc.
and then came to CVS/SVN menus which is when
I started asking questions and people pointed me
to CoCreateInstance() etc. (So perhaps I was
asking the wrong questions). I'll look into what
you've written and see if that answers what is
needed.
Thanks again.
Pete

"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:43e3d7cb$1 (AT) newsgroups (DOT) borland.com...
Quote:

"Pete Fraser" <pete.fraser (AT) frasersoft (DOT) nospam.com> wrote in message
news:43e3a567$1 (AT) newsgroups (DOT) borland.com...

I tried that and it didn't add anything to the menu :(

Works fine when I use it.

Was that because the WM_COMMAND was not being handled?

No. The WM_COMMAND message only applies when a menu item is actually
clicked on. The message contains the ID of the item that was clicked.
You
can pass that ID to IContextMenu::InvokeCommand() to execute the item's
action.

Incidently, during all of this discussion, you have only been loading the
menu for a specific plugin, not for a folder (which was your original
goal).
To get the entire menu for a folder, you do not use CoCreateInstance() at
all. Use the IShellFolder interface instead.
Back to top
Colin B Maharaj
Guest





PostPosted: Sun Feb 05, 2006 2:00 am    Post subject: Re: DCOM events WindowsXP SP2 Reply with quote



Hi, I must proclaim that I have not done much DCOM stuff in Builder but
I know of connection concerns that appeaars to be broken in WinXP SP2
and have some administative work arounds...

http://www.ct2k.com/cns2006/CT2K-XPDCOM.ppt

Note this presentation has notes specific to the application it supports
I hope you do not get too confused...

Hope this helps...


Mauro Tronto wrote:
Quote:
How can I implement a COM server and expect to support remote activation by
a non-administrative COM client or remote unauthenticated calls in WindowsXP
service pack 2?

How can I call "Advise" method from unauthenticated client in
ConnectionPoint scenario (callback)without having "Access denied" return
code?

Example:

TComInterface< IConnectionPointContainer, &IID_IConnectionPointContainer
cpc;
OLECHECK( p->QueryInterface( IID_IConnectionPointContainer,
(void**)&cpc ) );

TComInterface< IConnectionPoint, &IID_IConnectionPoint > cp;
OLECHECK( cpc->FindConnectionPoint( DIID_ITestEvents, &cp ) );

DWORD wCookie;
OLECHECK( cp->Advise( pk, &wCookie ) ); // ACCESS DENIED (if I check
ANONYMOUS user for REMOTE ACCESS everithink is right)

Thanks in advance for any help
Mauro Tronto

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Feb 06, 2006 11:00 pm    Post subject: Re: COM: Delphi code to BCB - how ? Reply with quote

"doffer" <fer (AT) nowdtderwe (DOT) kl> wrote:

Quote:
Well i then thought it would be very simple just to
convert this into BCB C++, but what i could see from
the net was that its much more complex in C++ - that
i need to use CoCreateInstance (and i have no idea
what the parameters should be ? ).

That depends on what the Type Library looks like for the COM object, but in general if you import the Type Library into C++, then the wrapper classes that the IDE generates will help your C++ code resemble the Delphi code. For example:

TCOMICServer CSServer;

CoInitialize(NULL);

CSServer = TCSServer::Create();
try
{
CSServer->ServerName = WideString("servername");
CSServer->Items->Add(WideString("new item"));

// Event
OPCServer->DataReadyEvent = OnDataEvent;
//...


Gambit
Back to top
Perseid
Guest





PostPosted: Tue Feb 14, 2006 4:03 am    Post subject: Re: MS-Excel: Get a count of worksheets in Excel... Reply with quote

"Armando" <villas1k (AT) gmail (DOT) com> Spat the Words

Quote:
Hi,

I have tried (in vain) to get a count of worksheets in an excel file. I
can open Excel, open a workbook, but I don't know how to get a count of
the Worksheets available in a workbook.

//To open the application
Variant XL
XL = Variant::CreateObject("excel.application");
XL.OlePropertySet("Visible", false);
//Open a Workbook
XL.OlePropertyGet("Workbooks").OleProcedure("open", StrFileName);

//Here I would like to get a count of the Worksheets
int iCount =

//Quit the Application...
XL.OleProcedure("Quit");
XL = Unassigned;

Thanks for any help.

Armando




This seems to work on my system:


void __fastcall TForm1::Button2Click(TObject *Sender)
{
Variant XL, WorkBooks, WorkBook, Sheets;
WideString StrFileName = "F:\\Win32\\ProjectsTest\\ExcelAutomate\\Book1.xls";
int iCount;

XL = Variant::CreateObject("excel.application");
XL.OlePropertySet("Visible", true);
WorkBooks = XL.OlePropertyGet("WorkBooks");
WorkBook = WorkBooks.OleFunction("Open", StrFileName);
Sheets = WorkBook.OlePropertyGet("Sheets");
iCount = Sheets.OlePropertyGet("Count");
// iCount now holds the number of sheets in the workbook

int i;
i=0;

//Quit the Application...
//XL.OleProcedure("Quit");
//XL = Unassigned;
}


Each copy of ms office ships with complete help documentation
for all com objects available to the programmer. Typically this is
located in \OfficeInstallFolder\Office10\1033\ and the one for
Excel is \OfficeInstallFolder\Office10\1033\VBAXL10.CHM
Back to top
David Pratt
Guest





PostPosted: Sun Mar 26, 2006 6:03 am    Post subject: Re: .NET TLB import ambiguity Reply with quote

"Mark Brown" <marknospampleasebrown (AT) iseincnospam (DOT) biz> wrote in message
news:433bed34$1 (AT) newsgroups (DOT) borland.com...
Quote:
Hi-

I recently created a .NET assembly, registered it using REGASM and
generated a type library. After importing the type library into C++
Builder 6 using Project->Import Type Library..., a TLB.cpp and .h file
were correctly generated. This type library references Mscorlib_tlb, as
it appears all .NET assemblies will.

Including the .NET tlb's header file into my source code, and compiling
generates the following errors:

E2015 Ambiguity between 'Exception' and 'Sysutils::Exception'

I've seen this problem posted many times, but no solutions. If I go ahead
and comment out the typedef for Exception in Mscorlib_tlb.h, I'll
eventually get another error:

E2015 Ambiguity between '_Module' and 'Mscorlib_tlb::_Module'

I'm guessing there will be more.

What are the steps needed for my COM Server to access my .NET assembly
using CCW?

Thanks,
Mark
You could try using a namespace declaration in mscorlib_tlb.h, and use the

namespace for scope resolution in your source code; problem is, if you
reimport the tlb for some reason, you'll have to redo the namespace
declaration again in the header file.
Back to top
Mirja Uusitalo
Guest





PostPosted: Wed Mar 29, 2006 8:03 am    Post subject: Re: Convert Interface to CComObject Reply with quote

"tinyabs" <nospam (AT) me (DOT) com> wrote in message
news:436830f4$1 (AT) newsgroups (DOT) borland.com...
Quote:
Hi, take a look at following code.

// In AnotherImpl.cpp - this function takes a IMyObject, read custom
fields I defined and do something.

STDMETHODIMP TAnotherImpl::DoSomething(IMyObject* myObject)
{
CComObject<TMyObjectImpl>* obj = myObject; // this doesn't work.
String sz = obj->SomeField;
};

CComObject<TMyObjectImpl> is provide in my ActiveX library. How do I cast
IMyObject into CComObject<TMyObjectImpl> so that I can have access to
fields inside it.

Thanks.

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Mar 29, 2006 12:03 pm    Post subject: Re: Convert Interface to CComObject Reply with quote

"Mirja Uusitalo" <mirja.uusitalo (AT) nethawk (DOT) fi> wrote in message
news:442a36c3 (AT) newsgroups (DOT) borland.com...

Quote:
CComObject<TMyObjectImpl>* obj = myObject; // this doesn't work.

Of course not, because that is not the way to use CComObject or
TMyObjectImpl to begin with. You should be accessing the IMyObject's
properties andmethods directly:

STDMETHODIMP TAnotherImpl::DoSomething(IMyObject* myObject)
{
String sz = myObject->SomeField;
};

If SomeField is private to TMyObjectImpl and not accessible through the
IMyObject interface, then you cannot simply cast the IMyObject to
TMyObjectImpl. TMyObjectImpl would have to private a private interface that
TAnotherImpl can quite for, ie:
..
STDMETHODIMP TAnotherImpl::DoSomething(IMyObject* myObject)
{
TComInterface<IPrivateObject> myPrivate = myObject;
if( myPrivate )
String sz = myPrivate->SomeField;
};

Otherwise, you will have make SomeField publically accessible from IMyObject
directly.

Quote:
CComObject<TMyObjectImpl> is provide in my ActiveX library. How
do I cast IMyObject into CComObject<TMyObjectImpl

You can't. Not safely, anyway.


Gambit
Back to top
Gary England
Guest





PostPosted: Thu Apr 13, 2006 10:03 am    Post subject: Re: Exception using COM with BDS2006 in TAutoDriver Reply with quote

Repeat posting as a reply...

There seems to be a problem with the code generation for the
TAutoDriver<T>::Unbind method in BDS 2006. It appears to be similar in
nature to that reported by Ken Wilkinson on 21/01/2006

I have imported an ActiveX control (LEADTools Imaging Main Control), and the
typelib importer has used the TAutoDriver<> template class to wrap the main
interface to the control. I have seen other controls imported using the
TComInterface<> template - I guess it depends on the implementation of the
ActiveX control as to which type of interface is used

When a method of the ActiveX control is called, I get an access violation in
the TAutoDriver<>::Unbind method.

When investigating this, I saw a number of oddities

1. The debugger does not show the members of the TAutoDriver<IDispatch>
class properly

2. When examinining the assembler, it seems that there is a 8 byte offset
from the "this" pointer value of the TAutoDriver<> instance and its first
data member (m_Dispatch). This is apparent in the constructors for the class

3. The 8 byte offset appears in the TAutoDriver<IDispatch>::Unbind method
assembler, but NOT in the TAutoDriver<_DLead> method (_DLead is the
interface for the control I am using). It appears to be this mismatch that
is causing the problem - the Unbind method uses m_Dispatch to dereference
the ActiveX object, but the TAutoDriver<_DLead>::Unbind method uses an
offset of 0 from the "this" pointer rather than 8 used for other method

In these circumstances, it is difficult to know exactly what is happening,
specifically

1. Is the 8 byte offset from the "this" pointer to "m_Dispatch" member
correct for the TAutoDriver<> class ?

2. If it is, then why does the debugger show it incorrectly for
TAutoDriver<IDispatch> but not TAutoDriver<_DLead> ?

3. Is the correct behaviour to have a 0 byte offset, but the code seems to
run mostly OK because the erroneous offset is consistent?

There is a workaround to this problem by using the interface pointer
directly. I modified the "GetDefaultInterface" method to return the
interface pointer (_DLead*) directly

return (_DLead*) m_OCXIntf; // m_OCXIntf is of type TAutoDriver<_DLead>

I suspect there is a problem with code generation with the template classes.
This may only affect ActiveX controls.

As an aside, does anyone know of a channel (other than this forum, or a paid
support contract) that you can use to submit bug reports to Borland? I don't
expect any commitment to fix the error or indeed any response without paying
for support, but I would like to know that someone within Borland actually
gets this information

Best Regards,

Gary England

"ken wilkinson" <ken.wilkinsonNoWay (AT) tetratech (DOT) com> wrote in message
news:43d12fc7$1 (AT) newsgroups (DOT) borland.com...
Quote:
Using BDS2006, Update 1, with FarPoint Spread COM, I get an exception in
Utilcls.h at

template <class DISPINTF> void
TAutoDriver<DISPINTF>::Unbind(bool release)
{
if (release && m_Dispatch)
m_Dispatch->Release();
m_Dispatch = 0;
}

or

template <class DISPINTF
TAutoDriver<DISPINTF>::~TAutoDriver()
{
Unbind();
}

The error message is
"First chance exception at $7C81EB33. Exception class EAccessViolation
with
message 'Access violation at address 00408615 in module 'MyApp.exe'. Read
of
address B2D88B5B'. Process MyApp.exe (1184)"


My code looks like this:
Spread1->LoadFromFile( WideString("test.ss7").c_bstr() );
or
Spread1->LoadFromFile( WideString("test.ss7") );

Both fail.

I see that there have been corrections in Utilcls.h in the past.
Any suggestions for BDS2006?
-Ken

Back to top
vavan
Guest





PostPosted: Mon Apr 17, 2006 7:03 am    Post subject: Re: Exception using COM with BDS2006 in TAutoDriver Reply with quote

On Thu, 13 Apr 2006 10:22:08 +0100, "Gary England"
<gengland (AT) spamless (DOT) com> wrote:

Quote:
As an aside, does anyone know of a channel (other than this forum, or a paid
support contract) that you can use to submit bug reports to Borland? I don't

please visit qc.borland.com

--
Vladimir Ulchenko aka vavan
Back to top
Gary England
Guest





PostPosted: Mon Apr 17, 2006 12:03 pm    Post subject: Re: Exception using COM with BDS2006 in TAutoDriver Reply with quote

Thanks

"vavan" <VavanRemove (AT) ThisSantel (DOT) ru> wrote in message
news:s8c642d2k7vbvllut2f7caqtav0bgqd8u5 (AT) 4ax (DOT) com...
Quote:
On Thu, 13 Apr 2006 10:22:08 +0100, "Gary England"
gengland (AT) spamless (DOT) com> wrote:

As an aside, does anyone know of a channel (other than this forum, or a
paid
support contract) that you can use to submit bug reports to Borland? I
don't

please visit qc.borland.com

--
Vladimir Ulchenko aka vavan
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (ActiveX) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.