Avatar of pin_plunder
pin_plunder

asked on 

what's wrong with this code?

void __fastcall TfrmListado::dbgridCellClick(TColumn *Column)
{
 if (Column->Index == 1)
    {
    wchar_t *tempURL;
    wchar_t *URL;
    URL = Column->Field->Text.WideChar(tempURL, 1000);
    CppInternetExplorer->Navigate(URL);
    }
}

it compiles, but it doesn't do what i want it to.

The thing is that in one column of my dbgrid there are lots of URL listed so what i want to do is that when they click one of these cells, the default browser is opened displaying the document.

any ideas. please give me code. (i'm using bc++ builder)
thanks.
C++

Avatar of undefined
Last Comment
pin_plunder
Avatar of jmccay
jmccay

>URL = Column->Field->Text.WideChar(tempURL, 1000);

  Does "Column->Field->Text.WideChar" actually allocate memory for the pointer tempURL?  You appear to allocate memory for either URL or tempURL.  Without knowing the more information about the specfic classes, that is all I can see wrong.
Avatar of snifong
snifong
Flag of United States of America image

If you are not sure whether or not it allocates do:
void __fastcall TfrmListado::dbgridCellClick(TColumn *Column)
{
 if (Column->Index == 1)
    {
    wchar_t *tempURL = NULL;
    wchar_t *URL = NULL;
    URL = Column->Field->Text.WideChar(tempURL, 1000);
    CppInternetExplorer->Navigate(URL);
    }
}
If it is not allocating memory you'll get an access violation. I bet that is the problem.
Avatar of pin_plunder
pin_plunder

ASKER

that's not the problem. the code compiles well, but the thing is that the explorer windows is not even opened.

see what i mean. (i;m sure the problem is in the WideChar conversion, but as i'm not used to c++ yet I'm asking for help)

thanks
Avatar of pin_plunder
pin_plunder

ASKER

not answered
Avatar of pin_plunder
pin_plunder

ASKER

This question has a deletion request Pending
Avatar of jmccay
jmccay

This question no longer is pending deletion
Avatar of jmccay
jmccay

  I still not convinced that any memory for the variables tempURL and URL is ever allocated.  Those are just pointers to wide characters.  Did you try allocating some memory for them?  This could cause the unexpected results.

  You won't necessarily get an access violation.  On non-NT machines, the memory is not quite so closely watch, and I have found I don't always get an access violation when I have memory leaks in my program.  NT watches memory more closely and catches more access violations that the other OSes don't.  

   Another problem yo may have is the scope of your two variables is just for that function.  The variables will not be available out side of it.

   What does "CppInternetExplorer->Navigate(URL);" do?  It would appear to just get the URL.  Have you already opened explorer prior to calling this function?  I don't have documentation for that available here.

   
Avatar of pin_plunder
pin_plunder

ASKER

it is true that, at first, I didn't allocate any memory for tempURL and URL, but that problem was solved (I believe) using the code snifong gave me.
   wchar_t *tempURL = NULL;
   wchar_t *URL = NULL;
is this OK? if not please give me code.

thanks.
   

ASKER CERTIFIED SOLUTION
Avatar of jmccay
jmccay

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of pin_plunder
pin_plunder

ASKER

ok. problem solved. memory was finally asigned for URL. But my question here is why doesn't this code open Internet Explorer.
I get a 'invalid variant operation' error.
(The internet explorer server control I am using is included only in C++ Builder 5, if I'm not wrong)

the code I'm using now is the following:

void __fastcall TfrmListado::dbgridCellClick(TColumn *Column)
{
 if (Column->Index == 1)
    {
    wchar_t *URL;
    URL = new wchar_t[100];
    Column->Field->Text.WideChar(URL, 100);
    CppInternetExplorer->Navigate(URL, TNoParam(), TNoParam(), TNoParam(), TNoParam());
    delete [] URL;
    }
}

thanks.
Avatar of jmccay
jmccay

 I don't think I will be able to help you much on that, but I can offer some general suggestions.  Look at the help for the control.  Also, make sure that you have done everything that is required to setup the control.  It might just be one option that you haven't set right.  I only have C++Builder 3.0 at home, and VC++6.0 at work.
Avatar of pin_plunder
pin_plunder

ASKER

ok. However I have just solved the problem, thanks though.              
Avatar of pin_plunder
pin_plunder

ASKER

This question has a deletion request Pending
Avatar of jmccay
jmccay

This question no longer is pending deletion
Avatar of jmccay
jmccay

  DO you want me to submit my first answer (to original question) as an answer or are you going to give credit to someone else?
Avatar of pin_plunder
pin_plunder

ASKER

Comment accepted as answer
Avatar of pin_plunder
pin_plunder

ASKER

sorry, I forgot about this.
thanx for reminding me.
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo