Options

using(PennyArcade.Forum){Threads.push(ProgrammingThread())}

15758596062

Posts

  • Options
    ecco the dolphinecco the dolphin Registered User regular
    edited May 2010
    clsCorwin wrote: »
    Jasconius wrote: »
    obfuscated c

    Pfft.

    Assembly is too easy to read. Obfuscated C at least tries.

    But really:

    MUMPS is practically obfuscation by design.

    I think someone here works with it?

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • Options
    LittleBootsLittleBoots Registered User regular
    edited May 2010
    clsCorwin wrote: »
    Jasconius wrote: »
    obfuscated c

    Pfft.

    Assembly is too easy to read. Obfuscated C at least tries.

    But really:

    MUMPS is practically obfuscation by design.

    I think someone here works with it?

    D:

    LittleBoots on

    Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    edited May 2010
    clsCorwin wrote: »
    Jasconius wrote: »
    obfuscated c

    Pfft.

    Assembly is too easy to read. Obfuscated C at least tries.

    But really:

    MUMPS is practically obfuscation by design.

    I think someone here works with it?

    D:

    Oh.

    I misremembered.

    He's working with a descendent of MUMPS.

    I am so sorry templewulf.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • Options
    LetarianLetarian Registered User regular
    edited May 2010
    How about the title is in Ook# - http://bluesorcerer.net/esoteric/ook.html

    Letarian on
  • Options
    MKRMKR Registered User regular
    edited May 2010
    Letarian wrote: »
    How about the title is in Ook# - http://bluesorcerer.net/esoteric/ook.html

    If only so it can be posted with this:
    23saucx.png

    MKR on
  • Options
    HalibutHalibut Passion Fish Swimming in obscurity.Registered User regular
    edited May 2010
    How about whitespace?

    Halibut on
  • Options
    MKRMKR Registered User regular
    edited May 2010
    I like LOLCODE.
    HAI
     CAN HAS STDIO?
     PLZ OPEN FILE "LOLCATS.TXT"?
         AWSUM THX
             VISIBLE FILE
         O NOES
             INVISIBLE "ERROR!"
     KTHXBYE
    

    MKR on
  • Options
    StarfuckStarfuck Registered User, ClubPA regular
    edited May 2010
    Starfuck wrote: »
    quick question for a java noob
    I'm just trying to write some functions to query a SQL Server db, so I looked up some stuff and I'm trying to use the JTDS driver. Downloaded it and dropped the .jar file in C:\Program Files\Java\jre1.6.0_07\lib is that correct?
    Because I get a ClassNotFoundException when I do this
    Class.forName("net.sourceforge.jtds.jdbc.Driver");

    I should probably go grab Head First Java or something, but I'm not doing anything too complicated.

    got past hurdle one
    had to install to the ext folder in libs
    C:\Program Files\Java\jre1.6.0_07\lib\ext

    on my way to being pro

    Starfuck on
    jackfaces
    "If you're going to play tiddly winks, play it with man hole covers."
    - John McCallum
  • Options
    MKRMKR Registered User regular
    edited May 2010
    How does one keep a WebBrowser control in C# from navigating when a user clicks? I want to be able to force it to open links in a new browser window. I tried setting .Url to the URL I wanted it to stay on in the _Navigating event handler, but that didn't work.

    The way I'm trying to do it is causing a weird StackOverflowException in winforms that can't be caught, so I don't think I'm doing it right. It felt hackish anyway, so I wasn't expecting it to work.

    MKR on
  • Options
    iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited May 2010
    MKR wrote: »
    How does one keep a WebBrowser control in C# from navigating when a user clicks? I want to be able to force it to open links in a new browser window. I tried setting .Url to the URL I wanted it to stay on in the _Navigating event handler, but that didn't work.

    The way I'm trying to do it is causing a weird StackOverflowException in winforms that can't be caught, so I don't think I'm doing it right. It felt hackish anyway, so I wasn't expecting it to work.
    In your Navigating handler, have you tried setting e.Cancel = true? That should cause the control to stop the event (stop Navigating), and then allow you to pop open the e.Url property in a new window.

    ... should. :D

    iTunesIsEvil on
  • Options
    MKRMKR Registered User regular
    edited May 2010
    MKR wrote: »
    How does one keep a WebBrowser control in C# from navigating when a user clicks? I want to be able to force it to open links in a new browser window. I tried setting .Url to the URL I wanted it to stay on in the _Navigating event handler, but that didn't work.

    The way I'm trying to do it is causing a weird StackOverflowException in winforms that can't be caught, so I don't think I'm doing it right. It felt hackish anyway, so I wasn't expecting it to work.
    In your Navigating handler, have you tried setting e.Cancel = true? That should cause the control to stop the event (stop Navigating), and then allow you to pop open the e.Url property in a new window.

    ... should. :D

    I didn't even think about e. I'll try that after I make these ramen noodles.

    edit: Success!
    private void txtFeedContent_Navigating(object sender, WebBrowserNavigatingEventArgs e)
            {
                if(e.Url != new Uri(currenturl))
                {
                    e.Cancel = true;
                }
                //Code to open link in default browser goes here
            }
    

    edit: Screenshot for the curious: http://i46.tinypic.com/2mnkxaw.png

    MKR on
  • Options
    bowenbowen How you doin'? Registered User regular
    edited May 2010
    Raaaaah @ .NET 3.0 installation crapping out and making everything think .NET 3.0 is installed.

    My thumbnail generator that ties into the Windows Shell doesn't work on computer with bogus installs. Now I gotta troubleshot this beast.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    EndEnd Registered User regular
    edited May 2010
    .NET installation problems are the bane of my existence.

    It does keep log files, which was the only way I found out there was a permission problem on a directory it was trying to install to (what) the last time I had issues.

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpg
  • Options
    iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited May 2010
    bowen wrote: »
    Raaaaah @ .NET 3.0 installation crapping out and making everything think .NET 3.0 is installed.

    My thumbnail generator that ties into the Windows Shell doesn't work on computer with bogus installs. Now I gotta troubleshot this beast.
    Gotta be careful with that. You're doing an "in-process shell extension" right there, ja?

    CLR program manager Jesse Kaplan thinks that's a bad idea.

    iTunesIsEvil on
  • Options
    bowenbowen How you doin'? Registered User regular
    edited May 2010
    bowen wrote: »
    Raaaaah @ .NET 3.0 installation crapping out and making everything think .NET 3.0 is installed.

    My thumbnail generator that ties into the Windows Shell doesn't work on computer with bogus installs. Now I gotta troubleshot this beast.
    Gotta be careful with that. You're doing an "in-process shell extension" right there, ja?

    CLR program manager Jesse Kaplan thinks that's a bad idea.

    Yeah he's also a giant dumbfuck too; Microsoft Office's giant COM library being partially written in .NET being the biggest reason. I'm not too worried because, really, the only thing that's used on the system is my application anyways.

    I could just change it to call interop services on shell32.dll as well, though, or whatever.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    MKRMKR Registered User regular
    edited May 2010
    Blargh

    I'm trying to handle a click on a link in the WebBrowser:
    string htmlfile = @"<html><head><title>";
                htmlfile = htmlfile + title + @"</title></head><body>";
                htmlfile = htmlfile + @"Open in browser: <a href='" + url + @"'" + @" onclick='window.external.URLClicked('" + url.Replace("\"", @"'") + @"')'>" + title + @"</a>" + body + @"</body>";
    

    (the code will look less ugly later)


    A sample result, which looks fine:
    Open in browser: <a href='http://xkcd.com/744/' onclick='window.external.URLClicked('http://xkcd.com/744/')'>Walkthrough</a>
    

    My URLClicked method, inside the form with the control:
    private void URLClicked(string url)
            {
                MessageBox.Show("Clicked a link");
            }
    

    I get a syntax error at line 2, character 1. Even though there's only one line. I'm doing it exactly as several examples have done it as far as I can tell.

    MKR on
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited May 2010
    If you do or have done development at a large corporation, you owe it to yourself to read up on the Politics-Oriented Development Process

    Senjutsu on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited May 2010
    Is there any actual performance advantage to using #define for constants as opposed to just doing int whatever = 0

    Jasconius on
  • Options
    MKRMKR Registered User regular
    edited May 2010
    Jasconius wrote: »
    Is there any actual performance advantage to using #define for constants as opposed to just doing int whatever = 0

    I doubt it matters much with modern compilers, but I doubt ancient ones handled both equally well.

    MKR on
  • Options
    KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    edited May 2010
    Jasconius wrote: »
    Is there any actual performance advantage to using #define for constants as opposed to just doing int whatever = 0

    No. But you can cause all sorts of interesting bugs due to scoping and macro expansion if you use #DEFINE. Remember that the preprocessor macro expansion can and will replace anything that matches the define in all files that include the header you declared the #DEFINE in.

    Ugh. I spent 2 days one time trying to track down a weird bug which turned out to be dueling #DEFINE TRUE statements in header files from two different groups that were getting included in the final build. And in that case, last one in wins.

    I really don't miss C/C++ all that much.

    Kakodaimonos on
  • Options
    GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited May 2010
    Jasconius wrote: »
    Is there any actual performance advantage to using #define for constants as opposed to just doing int whatever = 0

    If you don't tack a 'const' on to that, then yes, it handles them differently. It can't optimize the value as a constant (as it could with a #define, because it is a constant then) unless you mark it const. Some compilers still will (I believe Visual C++ and gcc will still do some static analysis and figure out it's actually constant), but it's still good practice to mark it const.

    If you do that, mark the int flag const, then no, there is no difference, and in fact, you shouldn't use #define. Use enums or constant ints.

    GnomeTank on
    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited May 2010
    Well I don't think an enum is relevant here.

    What I am doing is tracking a set of integer values such as X/Y coordinates that don't change they represents positions of UI elements during pre-defined states, and there's a lot of them. Like... i have 15 right now and I'm probably only halfway done.

    They get called at least a few times in a typical application usage. They are very specifically named, so there is no possibility for conflicts...

    but I should use constants anyway because: ??

    Jasconius on
  • Options
    EndEnd Registered User regular
    edited May 2010
    I usually use #defines out of habit, but I don't exactly write a lot of C code.

    There might be some scoping concerns with consts? ...but that'd probably be easily avoided by just marking them static (particularly if it's in a header).

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpg
  • Options
    Steel AngelSteel Angel Registered User regular
    edited May 2010
    Anyone here familiar with the Google maps API? I've got an idea for a project to automate some boring stuff I have to do every now and then and was wondering if it's possible to feed lists of partial addresses (usually missing city and zip code) and retrieving the full address instead of having to do it one by one by copy and paste.

    Steel Angel on
    Big Dookie wrote: »
    I found that tilting it doesn't work very well, and once I started jerking it, I got much better results.

    Steam Profile
    3DS: 3454-0268-5595 Battle.net: SteelAngel#1772
  • Options
    ASimPersonASimPerson Cold... and hard.Registered User regular
    edited May 2010
    Jasconius wrote: »
    Well I don't think an enum is relevant here.

    What I am doing is tracking a set of integer values such as X/Y coordinates that don't change they represents positions of UI elements during pre-defined states, and there's a lot of them. Like... i have 15 right now and I'm probably only halfway done.

    They get called at least a few times in a typical application usage. They are very specifically named, so there is no possibility for conflicts...

    but I should use constants anyway because: ??

    consts are technically safer, I guess. I dunno, I program C for a living and I pretty much always use defines for stuff like this.

    Maybe consts are a little more efficient because the compiler will only allocate storage for it once? Then again, I would imagine consts wouldn't be stored in the static section anyway if we're talking about integers and they resolve to ASM immediates.

    We need a real C guru for this one. eecc?

    ASimPerson on
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    edited May 2010
    ASimPerson wrote: »
    Jasconius wrote: »
    Well I don't think an enum is relevant here.

    What I am doing is tracking a set of integer values such as X/Y coordinates that don't change they represents positions of UI elements during pre-defined states, and there's a lot of them. Like... i have 15 right now and I'm probably only halfway done.

    They get called at least a few times in a typical application usage. They are very specifically named, so there is no possibility for conflicts...

    but I should use constants anyway because: ??

    consts are technically safer, I guess. I dunno, I program C for a living and I pretty much always use defines for stuff like this.

    Maybe consts are a little more efficient because the compiler will only allocate storage for it once? Then again, I would imagine consts wouldn't be stored in the static section anyway if we're talking about integers and they resolve to ASM immediates.

    We need a real C guru for this one. eecc?

    Haha, I'm flattered, but I'm not a guru.

    Besides, I'm going to end up repeating what you guys have said.

    I believe that once you turn on optimisation, it won't make a difference.

    But then, as is always the case with programming, there are a whole bunch of caveats depending on what the const variable is, and how it's used.

    e.g. provided you never try to take the address of the variable.

    void putPoint( const int *pOptionalLocation );
    #define DEFAULT_LOCATION 6
    putPoint( & DEFAULT_LOCATION ); // Good luck with this.
    

    vs
    const int nDefaultLocation = 6;
    putPoint( & nDefaultLocation ); // Works as expected
    

    or the classic:
    const char *pData = "Blah blah blah"; // Will practically always be allocated
    

    Which is really a specific case of the more general guideline that arrays of const variables will almost always be allocated*:

    e.g.
    const int nDefaultLocations[ 6 ] = { 3, 2, 7, 1, 3, 8 };
    

    * Again, always caveats:
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
      const int a[5] = { 2, 3, 6, 8, 2 };
    
      printf("&#37;d", a[3]);
    
      return 0;
    }
    

    Will not allocate the array, but will become the equivalent of (with optimisations):
    int main(int argc, char *argv[])
    {
      printf("%d", 8);
    
      return 0;
    }
    
    Whereas:
    int main(int argc, char *argv[])
    {
      int nIndex;
    
      printf("%d\n", getData(3));
    
      return 0;
    }
    
    int getData(int nIndex)
    {
      const int a[5] = { 2, 3, 6, 8, 2 };
    
      return a[nIndex];
    }
    

    would allocate the memory on the stack (check out the assembly produced by gcc! It's fascinating!)
    _getData:
            pushl   %ebp
            movl    %esp, %ebp
            subl    $40, %esp
            movl    $2, -40(%ebp)
            movl    8(%ebp), %eax
            movl    $3, -36(%ebp)
            movl    $6, -32(%ebp)
            movl    $8, -28(%ebp)
            movl    $2, -24(%ebp)
            movl    -40(%ebp,%eax,4), %eax
            leave
            ret
    

    It's decided that with only 5 elements, it's just cheaper to copy them into the stack via mov instructions!! Hahahaha!

    On the other hand, making the array static const int allocates it in static memory, which saves the time needed for initialisation at the expense of constant memory usage.

    Personally, unless a variable needs the specific advantages offered by a #define, I'd use a const because they turn into the same binaries most of the time. Also, #defines have a few disadvantages that can be hard to track down via compiler messages:
    #define SOME_VARIABLE  8
    
    void IHaveForgottenSomeVariableIsADefine(void)
    {
      SOME_VARIABLE = 2; // Whoops!
    }
    

    Actually, that error isn't so bad, it's in C++ where you can have something like
    // Oh noes!  Has global scope!
    #define MAX_VALUE 8
    
    class tExample
    {
      const int MAX_VALUE = 2;
    };
    

    On the other hand, #defines do offer some advantages - but they are quite specific, and you'd sort of know if you want to use them. I have seen it used in quite a few places (mostly pure C libraries), e.g.
    Say you're providing a library, and you'd like to have defaults that can be optionally user initialised:

    user_config.h : Custom user config file with stuff like:

    // Do this if you want to change the default number of foobars, otherwise leave undefined
    #define DEFAULT_FOOBARS 10

    // Do this if you want to change the default number of doohickeys, otherwise leave undefined
    // #define DEFAULT_DOOHICKEYS UNUSED

    And then a:

    default_config.h :

    #ifndef DEFAULT_FOOBARS
    #define DEFAULT_FOOBARS 60
    #endif

    #ifndef DEFAULT_DOOHICKEYS
    #define DEFAULT_DOOHICKEYS 21
    #endif

    etc

    library.c :

    #include "user_config.h"
    #include "default_config.h"

    // No matter what, DEFAULT_DOOHICKEYS and DEFAULT_FOOBARS are now defined to *something*

    int getDefaultFooBars(void)
    {
    return DEFAULT_FOOBARS;
    }

    Heck, you could try to error check to provide guarantees at compile time using this:

    #if DEFAULT_FOOBARS < 20
    // Report compile time error, e.g.
    #error "DEFAULT_FOOBARS must be greater than or equal to 20"
    #endif

    Again, these are some very specific cases where #defines can be more useful than consts, but you'd know if you want to use them.

    Now, having said all that, I'd be tempted to use a combination of enums and const int arrays for what I *think* Jasconius is describing:

    e.g.
    typedef enum _tUIElement
    {
      uie_OKButton = 0,
      uie_CancelButton,
      uie_StaticUserMessage,
      uie_EnumSize
    } tUIElement;
    
    const int g_nxLocation[ uie_EnumSize ] = 
    {
      10,
      20,
      0
    };
    
    int getXLocation( tUIElement uiElement )
    {
      if(uiElement >= uie_EnumSize || uiElement < 0)
        return -1;
    
      return g_nxLocation[uiElement];
    }
    
    

    just because if you use #defines, you might end up with something like:
    #define UI_OKBUTTON 0
    #define UI_OKBUTTONX 10
    
    #define UI_CANCELBUTTON 1
    #define UI_CANCELBUTTONX 20
    
    switch(uiElement)
    {
    case UI_OKBUTTON:
      return UI_OKBUTTONX;
    case UI_CANCELBUTTON:
      return UI_CANCELBUTTONX;
    default:
      return -1;
    }
    

    Which in the long run is a bit harder to maintain.

    e.g. add a new attribute - default enable state. Using #defines, you'd have to go:
    #define UI_OKBUTTONEN 1
    #define UI_CANCELBUTTONEN 0
    // ... carry on for each ui element
    

    using a const array:
    const int g_nDefaultEnable[ uie_EnumSize ] = 
    {
      1,
      0
    }
    

    You do have to make sure that the elements in the array are filled in properly and match their proper enum, though!

    That is a bug I've been bitten by before.

    Again, trade-offs:

    In embedded systems, you might find you have way more code space than stack space, so you use the #defines and the switch() because that's code space and doesn't take up the very limited memory you have!

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • Options
    AiranAiran Registered User regular
    edited May 2010
    This seems a little far fetched, but is it possible in C#/.NET to store a list of method names in an App.Config key (comma-separated), then have the program inspect the Config file, and run the specified methods?

    Building a web test suite, so would be nice to have this flexibility instead of recompiling the main class every time I want to make a new test sequence. I could use a unit test framework, but I'd like to explore this avenue first. Would Reflection be a good place to start?? Alternatively is there another way to achieve this 'read method names from file, run methods as listed' programatically?

    Airan on
    paDudSig.jpg
  • Options
    KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    edited May 2010
    Reflection is probably the better approach. That's how NUnit works. Reflection + custom attributes that are used to tag the test cases and test setups.

    You should take a look at NUnit and NUnitASP. It may do what you need:

    http://www.nunit.org/

    http://nunitasp.sourceforge.net/download.html

    Kakodaimonos on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited May 2010
    O.O eecc you are some sort of man god

    what I am describing but I think it's approaching that. These are the constants I have defined right now.
    #define kImgHeaderBackgroundFilePrefix @browse_header_bkg_
    #define kAutoCompletePopoverPortraitXCoordinate 380
    #define kAutoCompletePopoverPortraitYCoordinate 216
    #define kAutoCompletePopoverLandscapeXCoordinate 525
    #define kAutoCompletePopoverLandscapeYCoordinate 0
    #define kAutoCompletePopoverWidth 342
    #define kAutoCompletePopoverHeight 328

    #define kSearchBarPortraitXCoordinate 0
    #define kSearchBarPortraitYCoordinate 544
    #define kSearchBarLandscapeXCoordinate 0
    #define kSearchBarLandscapeYCoordinate 478
    #define kSearchBarResponderPortraitYCoordinate 659 // Y coordinate for when keyboard is displaying in portrait mode
    #define kSearchBarResponderLandscapeYCoordinate 316 // Y coordinate for when keyboard is displaying in landscape mode
    #define kSearchBarPortraitWidth 768
    #define kSearchBarPortraitHeight 38
    #define kSearchBarLandscapeWidth 1024
    #define kSearchBarLandscapeHeight 38

    So there's x/y/height/width for the elements for both device orientations, and there's a couple of extra values for application state, where, since only one value is different, you only see that one (in this case Y). There is no "ResponderWidth" since becoming a responder doesn't change the width of the control.

    Another way of doing this, and perhaps solidifying an answer is, instead of just storing my integer values and then creating the struct to which they fit as needed, I could just pre-define my array of structs and use the enum/array approach that eecc has provided, which seems pretty cool.

    That way my values get stored to satisfaction, and I am not creating a struct every time the user flips their device over. Not that I really need that performance. I was just curious. Regardless, the struct/enum/array approach seems easier to maintain from a code perspective.

    Jasconius on
  • Options
    MKRMKR Registered User regular
    edited May 2010
    MKR wrote: »
    Blargh

    I'm trying to handle a click on a link in the WebBrowser:
    string htmlfile = @"<html><head><title>";
                htmlfile = htmlfile + title + @"</title></head><body>";
                htmlfile = htmlfile + @"Open in browser: <a href='" + url + @"'" + @" onclick='window.external.URLClicked('" + url.Replace("\"", @"'") + @"')'>" + title + @"</a>" + body + @"</body>";
    

    (the code will look less ugly later)


    A sample result, which looks fine:
    Open in browser: <a href='http://xkcd.com/744/' onclick='window.external.URLClicked('http://xkcd.com/744/')'>Walkthrough</a>
    

    My URLClicked method, inside the form with the control:
    private void URLClicked(string url)
            {
                MessageBox.Show("Clicked a link");
            }
    

    I get a syntax error at line 2, character 1. Even though there's only one line. I'm doing it exactly as several examples have done it as far as I can tell.

    Anyone? And some kind of reference for Winforms would be awesome. I would get the O'Reily book to go with the C# 3.0 book that has been immensely helpful, but they don't seem to have one for WinForms.

    MKR on
  • Options
    bowenbowen How you doin'? Registered User regular
    edited May 2010
    So reading the H/A thread about the software job and the division problem makes me want to say, "What would I do if division/modulus was broken on my platform/library? I'd find a different job that doesn't require me to work with broken components or libraries or doesn't attempt to fix them before trying to integrate a half-assed-bug-filled implementation of bit shifting and division."

    One of my responses to the trivia answer in the past with a "towers of hanoi" was "I'd defer that question to the programming department that specializes in non-business oriented algorithms, then I'd continue with the project or task at hand that is probably more important. But, if you want to see my code from my C++ Class, I'll be happy to give it to you." I don't think he liked my response, but then again, when he offered me $9 an hour before that, he deserves whatever he gets.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    syndalissyndalis Getting Classy On the WallRegistered User, Loves Apple Products regular
    edited May 2010
    More Objective C fun here.

    Right now, I am generating three NSMutableArrays, all of which (by themselves) can drive a tableview. What I WANT to do is put these three arrays into a single NSMutabaleArray, and have that drive a sectioned tableView.

    My code in question is as follows:

    In my .M:
    - (void)viewWillAppear:(BOOL)animated {
    
    	NSMutableArray* mutableFetchResultsClasses = [CoreDataHelper searchObjectsInContext:@"CharacterClasses" :entitySearchPredicateClasses :@"Name" :YES :managedObjectContext];
    	self.entityArrayCharacterClasses = mutableFetchResultsClasses;
    
    	NSMutableArray* mutableFetchResultsRaces = [CoreDataHelper searchObjectsInContext:@"CharacterRaces" :entitySearchPredicateRaces :@"Name" :YES :managedObjectContext];
    	self.entityArrayCharacterRaces = mutableFetchResultsRaces;
    
    	NSMutableArray* mutableFetchResultsPowers = [CoreDataHelper searchObjectsInContext:@"CharacterPowers" :entitySearchPredicatePowers :@"Name" :YES :managedObjectContext];
    	self.entityArrayCharacterPowers = mutableFetchResultsPowers;
    
    	entityArrayCharacter = [[NSMutableArray alloc] init];
    	[self.entityArrayCharacter addObject:self.entityArrayCharacterClasses];
    	[self.entityArrayCharacter addObject:self.entityArrayCharacterRaces];
    	[self.entityArrayCharacter addObject:self.entityArrayCharacterPowers];
    
    	NSLog(@"&#37;i",[self.entityArrayCharacter count]);
    }
    
    And this is crashing out on me, giving the error:
    -[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x6faad80

    So building the parent array is really my first major hurdle. I know the search predicates are right, I know that the individual mutable arrays are good on their own; they pop into my plumbing perfectly if I simply rename their output to entityArrayCharacter and comment out thew rest of this code.

    Once I have the array, I THINK this is right below, but some insight would be awesome here as well...

    Also in my .M:
    #pragma mark Table view methods
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return [entityArrayCharacter count];
    //	NSLog(@"%i",[entityArrayCharacter count]);
    }
    
    
    // Customize the number of rows in the table view.
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    	
    		//Number of rows it should expect should be based on the section
    		NSDictionary *dictionary = [entityArrayCharacter objectAtIndex:section];
    		NSArray *array = [dictionary objectForKey:@"Name"];
    		return [array count];
    	}
    
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    	
    	if(section == 0)
    		return @"Classes";
    	else if(section == 1)
    		return @"Races";
    	else {
    		return @"Powers";
    	}
    }
    
    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    		
    		static NSString *CellIdentifier = @"Cell";
    		
    		UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    		if (cell == nil) {
    			cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    		}
    		
    		// Set up the cell...
    		
    		//First get the dictionary object
    		NSDictionary *dictionary = [self.entityArrayCharacter objectAtIndex:indexPath.section];
    		NSArray *array = [dictionary objectForKey:@"Name"];
    		NSString *cellValue = [array objectAtIndex:indexPath.row];
    		cell.text = cellValue;
    		
    		return cell;
    }
    
    Of course, this is all assumptions, as I haven't gotten my array to the point where this code is executing. I am sure I am missing something all kinds of simple here... would love some help though. My app is making HUGE strides, and little things like this keep me from trying to hit my deadline.

    syndalis on
    SW-4158-3990-6116
    Let's play Mario Kart or something...
  • Options
    GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited May 2010
    Seriously, don't use #define. Just use constant int's, where you can actually control the scoping (by putting them in a namespace or a class/struct). You also don't run the risk of incredibly hard to track down compiler problems caused by same-name #defines and other constructs.

    GnomeTank on
    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited May 2010
    You are putting NSMutableArrays into your parent array, but when you retrieve them in your table methods you are trying to assign them to NSDictionary ... why?

    Jasconius on
  • Options
    GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited May 2010
    MKR wrote: »
    MKR wrote: »
    Blargh

    I'm trying to handle a click on a link in the WebBrowser:
    string htmlfile = @"<html><head><title>";
                htmlfile = htmlfile + title + @"</title></head><body>";
                htmlfile = htmlfile + @"Open in browser: <a href='" + url + @"'" + @" onclick='window.external.URLClicked('" + url.Replace("\"", @"'") + @"')'>" + title + @"</a>" + body + @"</body>";
    

    (the code will look less ugly later)


    A sample result, which looks fine:
    Open in browser: <a href='http://xkcd.com/744/' onclick='window.external.URLClicked('http://xkcd.com/744/')'>Walkthrough</a>
    

    My URLClicked method, inside the form with the control:
    private void URLClicked(string url)
            {
                MessageBox.Show("Clicked a link");
            }
    

    I get a syntax error at line 2, character 1. Even though there's only one line. I'm doing it exactly as several examples have done it as far as I can tell.

    Anyone? And some kind of reference for Winforms would be awesome. I would get the O'Reily book to go with the C# 3.0 book that has been immensely helpful, but they don't seem to have one for WinForms.

    WinForms is incredibly well documented on MSDN, and a lot of other places. It's probably one of the most well documented and sampled toolkits in history (seriously).

    The syntax error may not be in that line of code, we would need to see the whole class (preferably spoilered so it isn't huge) to get an idea of where the syntax error is.

    GnomeTank on
    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • Options
    clsCorwinclsCorwin Registered User regular
    edited May 2010
    Really getting tired of php.

    Getting this error:
    Parse error: syntax error, unexpected '"' in /user/student/mfarrell/public_html/cs4250/adhoc.php on line 6

    Line 6 I'm using str_replace.

    Heres an example of str_replace from the PHP Manual
    $onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
    <?php
    include("dbinfo.inc.php");
    $temp_query = $_GET["AdhocQuery"];
    echo "$temp_query";
    $slash = "\";
    $query = str_replace($slash, "", $temp_query);
    
    $token = strtok($query, " ");
    
    $i = 0;
    $tables = array();
    $temp1 = array();
    $temp2 = array();
    $from = "FROM";
    $select = "SELECT";
    $distinct = "DISTINCT";
    
    while( strcmp($token, $from) != 0 )
    {
    	$temp1[$i] = $token;
    	$token = strtok(" ,");
    	$i++;
    }
    
    $i=0;
    echo "<br><br>";
    foreach( $temp1 as $value )
    {
    	if( strcmp($value, $select) != 0 )
    	{
    		echo "temp1 value = $value<br>";
    		$temp2[$i] = $value;
    		$i++;
    	}
    	$j++;
    }
    
    $i=0;
    foreach( $temp2 as $value )
    {
    	if( strcmp($value, $distinct) != 0 )
    	{
    		echo "temp2 value = $value<br>";
    		$tables[$i] = $value;
    		$i++;
    	}
    }
    
    $num = $i;
    
    echo "num = $num<br>";
    
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    
    $result = mysql_query($query);
    
    ?>
    <table border="1" cellspacing="2" cellpadding="2">
    <tr>
    <?php
    $i=0;
    while($i < $num)
    {
    	?>
    	<th><font face="Arial, Helvetica, sans-serif"><? echo "$tables[$i]" ?></font></th>
    	<?php
    	$i++;
    }
    ?>
    </tr>
    <?php
    
    while ($row = mysql_fetch_assoc($result))
    {
    	?>
    	<tr>
    	<?php
    	$i=0;
    	while($i < $num)
    	{
    		?>
    		<td><font face="Arial, Helvetica, sans-serif"><? echo $row[$tables[$i]]?></font></td>
    		<?php
    		$i++;
    	}
    	?>
    	</tr>
    
    	<?php
    
    
    
    }
    
    mysql_close();
    

    Edit: Nevermind. Escape character. Blargh.

    clsCorwin on
  • Options
    EtheaEthea Registered User regular
    edited May 2010
    GnomeTank wrote: »
    Seriously, don't use #define. Just use constant int's, where you can actually control the scoping (by putting them in a namespace or a class/struct). You also don't run the risk of incredibly hard to track down compiler problems caused by same-name #defines and other constructs.


    That is why you use #undef at the end of the file. #define is perfectly acceptable as long as you treat it with the proper amount of respect.

    Ethea on
  • Options
    GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited May 2010
    Ethea wrote: »
    GnomeTank wrote: »
    Seriously, don't use #define. Just use constant int's, where you can actually control the scoping (by putting them in a namespace or a class/struct). You also don't run the risk of incredibly hard to track down compiler problems caused by same-name #defines and other constructs.


    That is why you use #undef at the end of the file. #define is perfectly acceptable as long as you treat it with the proper amount of respect.

    And why do any of that when you can just use equally efficient constant integers that follow correct syntax and scoping rules?

    There is no point, at all, except wanting to be a crusty old codger who still thinks the pre-processor is a great idea.

    GnomeTank on
    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • Options
    EtheaEthea Registered User regular
    edited May 2010
    GnomeTank wrote: »
    Ethea wrote: »
    GnomeTank wrote: »
    Seriously, don't use #define. Just use constant int's, where you can actually control the scoping (by putting them in a namespace or a class/struct). You also don't run the risk of incredibly hard to track down compiler problems caused by same-name #defines and other constructs.


    That is why you use #undef at the end of the file. #define is perfectly acceptable as long as you treat it with the proper amount of respect.

    And why do any of that when you can just use equally efficient constant integers that follow correct syntax and scoping rules?

    There is no point, at all, except wanting to be a crusty old codger who still thinks the pre-processor is a great idea.

    I had a problem when you mentioned a problem that is caused by bad programming, not a bad language feature. As far as defines go, I personally like them as they people to write macros. And we all know macros are black magic.

    Ethea on
  • Options
    MKRMKR Registered User regular
    edited May 2010
    HTML.cs:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    
    namespace Showbox
    {
        class HTML
        {
            //There's probably a better way to do this.
            private string basepath = Application.StartupPath.Replace(@"\", @"/") + "/";
            private string filename = "HTML/index.html";
    
            public string GenerateHTML(string title, string csspath, string body, string url)
            {
                //Generates an HTML document and returns it
                string generatedpath = @"file:///" + basepath + filename;
                
    
                //csspath will hold the location of the css used to generate pages
                //temporary indicates whether or not the file is temporary. May end up not
                //using it.
                
                //Add a check to create the file if it doesn't exist
                TextWriter w = new StreamWriter(Application.StartupPath + @"\HTML\index.html");
                
                //Build a simple HTML file
    
                string htmlfile = @"<html><head><title>";
                htmlfile = htmlfile + title + @"</title></head><body>";
                htmlfile = htmlfile + @"URL: " + url + "</body>";
    
                //write to file
                w.WriteLine(htmlfile);
                //close file
                w.Close();
                return generatedpath;
            }
    
            public void DeleteGeneratedHTML()
            {
                //Stub for a method that deletes a generated HTML file.
                //Used when the program starts and exits
            }
    
        }
    }
    

    The relevant methods:
    private void URLClicked(string url)
            {
                MessageBox.Show("Clicked a link");
            }
            private void tsReloadFeeds_Click(object sender, EventArgs e)
            {
                currenturl = Application.StartupPath.Replace(@"\", @"/");
                //Refresh all feeds
                //run a check to make sure something is selected
                lstFeeds.Items.Clear();
                RSS rss = new RSS();
                List<string> RSSList = rss.LoadRSS(Application.StartupPath.Replace(@"\", @"/") + "/Feeds.xml", 0);
                TitleList = rss.GetTitleList();
                URLList = rss.GetURLList();
                DescriptionList = rss.GetDescriptionList();
    
    
                List<int> count = new List<int>();
    
                count = rss.GetCount();
                int i = 0;
                while (i != URLList.Count)
                {
    
    
                    ListViewItem item = new ListViewItem(TitleList[i]);
    
                    item.SubItems.Add(URLList[i]);
                    item.SubItems.Add(CountList[i].ToString());
    
                    lstFeeds.Items.AddRange(new ListViewItem[] { item });
                    i++;
                }
    
                //test
                HTML generator = new HTML();
                //MessageBox.Show(generator.GenerateHTML("test", "buh", true));
                string thefile = generator.GenerateHTML(TitleList[i - 1], "no css", DescriptionList[i - 1], URLList[i - 1]);
                txtFeedContent.Navigate(thefile.Replace(@" ", @"&#37;20"));
                //MessageBox.Show(thefile.Replace(@" ", @"%20"));
    
                currenturl = thefile;
            }
    
            private void txtFeedContent_Navigating(object sender, WebBrowserNavigatingEventArgs e)
            {
                //txtFeedContent.Url = URLList;
                //setting to the previous url to keep it from navigating
                //MessageBox.Show(e.Url.ToString());
                if(e.Url != new Uri(currenturl))
                {
                    e.Cancel = true;
                }
                //open link in default browser
                
            }
    

    The generated HTML and generated URL look correct when I have them show in a message box. There's no error when I click the link, only when I click the button that calls tsReloadFeeds_Click.

    edit: I forget that I took the onClick out of the anchor, but that's in the other post.

    MKR on
Sign In or Register to comment.