×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Mar 2004
    Posts
    73

    String parameters to TBuf::Format

    When I want to pass a string parameter to a Format, I can't say eg:
    Code:
    Item.Format (_L("%S\t%S"), &view.ColDes (2), &view.ColDes (2));
    in other words, to use any function that happens to return a string because the compiler warns about nonstandard extensions. Instead, I need to copy the strings first
    Code:
    TBuf<50> Item1 (view.ColDes (2));
    TBuf<50> Item2 (view.ColDes (3));
    Item.Format (_L("%S\t%S"), &Item1, &Item2);
    Am I missing something obvious? Or should I simply suppress the warning? I don't really like that second solution...

    Thanks,
    Gábor
    Last edited by djgtram; 2005-04-03 at 18:13.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Location
    Oulu, Finland
    Posts
    1,122
    The problem is that you're trying to take the address of a temporary variable: the return value of ColDes(). Since it's not standard C++, you'll get a warning. Both VC++ and GCC compilers can work around it so basically you could ignore the warning. But I'd suggest rewriting your code so that there are no warnings, ignored or otherwise. A better workaround than using TBufs could be like:
    Code:
    TPtrC Item1 (view.ColDes (2));
    TPtrC Item2 (view.ColDes (3));
    Item.Format (_L("%S\t%S"), &Item1, &Item2);
    (I'm assuming it's RDbView::ColDes you're calling - it returns a TPtrC).

    Lauri

  3. #3
    Regular Contributor
    Join Date
    Mar 2004
    Posts
    73
    It is indeed nicer this way. Thank you.

    Bye,
    Gábor

  4. #4
    Regular Contributor
    Join Date
    Mar 2004
    Posts
    73
    Strangely, the same approach doesn't work here:
    Code:
    TParsePtrC Parse (PathIn);
    TPtrC DriveAndPath (Parse.DriveAndPath ());
    TPtrC Name (Parse.Name ());
    PathOut.Format (_L("%S%S.dat"), &DriveAndPath, &Name);
    Sorry, it was a false alarm. I had aliases: one descriptor was a class member and the second—coming in through a function argument—happened to be the same descriptor. It works now but the forum didn't allow me to delete the post.

    Bye,
    Gábor
    Last edited by djgtram; 2005-04-03 at 22:29.

Posting Permissions

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