Simple component question

Results 1 to 4 of 4

Thread: Simple component question

  1. #1
    Ben Roy Guest

    Default Simple component question

    Can I access variables that exist on an ASP page in a component that is instantiated from that page? For instance (not proper syntax, just the idea behind it):<BR><BR>&#060;include;<BR>set obj = Component.Class<BR>strSomething = obj.Function<BR><BR>Now suppose there is a variable in "" that is strDBName. In the Function() in my component.dll file can I refer to strDBName? Seems to me that I probably should be able to since the variable scope should encompass the component, but I&#039m not sure if the component is allowed to interact with it&#039s creation enviroment that way. Maybe it seems like a dumb question but I&#039ve never done this before. =P<BR><BR>Thanks for any help here.

  2. #2
    Ian S Guest

    Default RE: Simple component question

    You sure can. This is a code sample directly from some<BR>of my code Im working on now:<BR><BR>&#060;%<BR>dim strConn<BR>strConn = Session("Str_Conn")<BR><BR>dim oService<BR>set oService = Server.CreateObject("WeatherObjs.WeatherService")< BR>oService.SubscriberID = lngSubscriberID<BR>oService.ConnectionString = strConn<BR>%&#062;<BR><BR><BR>You can see that I set the subscriber ID and connection string<BR>using variables. The strConn variable is actually generated<BR>by a function that reads a .ini file and assigns the data to<BR>a session variable. All of that code is in a include file.<BR><BR>*off topic note - You shouldn&#039t normally store your connection<BR>strings in a session variable unless they are dynamic and<BR>session specific.<BR><BR>I hope this helps some though :-)<BR>

  3. #3
    Ben Roy Guest

    Default RE: Simple component question

    My first reaction is...DUH! I should have thought of that. I can just variables as you were showing. What I was actually asking was if, from inside the component itself I could access a variable that was outside the component on the page. So in otherwords from inside WeatherObjs.Weatherservice class there would be a function which referred to "strConn". I guess I want to know if the component is aware and able to access information outside of itself. I should be able to use the method that you have here for what I want, but I&#039m still curious.

  4. #4
    Larrie Guest

    Default RE: Simple component question

    The answer is simply no. Another way of doing it would be to pass the variables as parameters into the function, eg.<BR><BR>set obj = Component.Class<BR>strSomething = obj.Function(strDBName, lngSubscriberID)<BR><BR>This way the object is not holding state.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts