need help regarding how to print to console I tried..................
| Thu, 2007-08-23 07:22 | |
|
I tried the following code....... Ttest3FileManager iFileStore; _LIT(KFileStorePresent,"FileStore Present\n\n"); if(iFileStore) I get following errror-> "undefined identifier console" Is there any "header files" and "librariies" I should include?? THANX IN ADVANCE!!!!!!!!!! |
|






Forum posts: 463
you need to construct console for that . Below is a rough example(note: I havent tested it though)
#include <e32base.h>
#include <e32cons.h>
LOCAL_C void MainL(void);
GLDEF_C TInt E32Main()
{
CTrapCleanup* cleanup=CTrapCleanup::New();
TRAPD(error,MainL());
delete cleanup;
return 0;
}
_LIT(KHello,"Hello");
LOCAL_C void MainL(void)
{
CConsoleBase *console=Console::NewL(KHello,TSize(KConsFullScreen,KConsFullScreen));
CleanupStack::PushL(console);
console->Printf(KHello);
console->Getch();
CleanupStack::PopAndDestroy();
}
Try to implement a similar thing for your code so that you might get the grasp of it faster.
Hope it helps
Good Luck and Cheers
Neil
Forum posts: 137
Thanx Niel for your help
I was able to print to console with the following code
------------------------------------------------------------------------
in ".h file"->
----------------------------------
#include < e32base.h>
#include < e32cons.h>
in the "cpp file"
-----------------------------------
_LIT(KFileStorePresent,"FileStore Present\n\n");
_LIT(KNoFileStore,"FileStore Not Present\n\n");
CConsoleBase *console;
if(ETrue)
{
console=Console::NewL(KFileStorePresent,TSize
(KConsFullScreen,KConsFullScreen));
CleanupStack::PushL(console);
console->Printf(KFileStorePresent);
}
else
{
console=Console::NewL(KNoFileStore,TSize
(KConsFullScreen,KConsFullScreen));
CleanupStack::PushL(console);
console->Printf(KNoFileStore);
}
console->Getch();
CleanupStack::PopAndDestroy();
There is no need of
LOCAL_C void MainL(void);
GLDEF_C TInt E32Main();
methods.
in fact including them gives errors.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
But I again have problems>>>>>>>>>
Ttest3FileManager iFileStore;
if(iFileStore) //this causes error
{
------
--------
}
So, how to chek if instance of a class is present or not?????????????
Forum posts: 1248
Do you mean that you want to look into the filestore and check whether a certain object is present or not? If yes, I don't know of any other way than writing additional information into the store when creating it.
Meaning: If a certain object can be present or missing, do not only write the object itself into the store, but write an additional, separate boolean *before* the object that basically says "Object present?". Reading then becomes trivial: Read the boolean, if it is false, stop, if it is true, continue to read the object.
René Brunner
Forum posts: 137
Sorry,
I meant to find out
if instance of a general class is still running i.e. a class is still alive in the program?????????????
Forum posts: 1248
I am afraid I don't understand your question. How can a class be "running" or "alive"?
You mean how to know whether you still have instances/objects of a certain class allocated in your program that you need to free before terminating the program? If yes: Well, you have to keep track yourself about the objects in your program...
René Brunner
Forum posts: 137
Yes you have got it right.
But is there no other way of testing it programatically???????
Forum posts: 1248
No, I am pretty sure that the Symbian framework does not offer some general mechanism to free objects, e.g. a pool that keeps all your objects and that you can query "Which objects are still there that I allocated?"
You have to keep track of each and every object that you allocate yourself and make sure that you free it accordingly. But I think you will see that this is not as hard as it may first sound
René Brunner
Forum posts: 137
I do not want to free any objects,
I want to write members of a class into stream from 2 different places in the program. It works good at one point but does not work in the other.
So, I am Checking if the class holding the data to be stored is still active.
So, the point is just to check if the instance of the class is present??
Forum posts: 1248
No idea what you are talking about.
Probably you should tell more about your problem, and also show some parts of your code. If you say "it does not work in the other", well, what happens?
If you have a pointer variable it is NULL if there is no object allocated and not NULL if the variable holds a pointer to an allocated object. But I am pretty sure that you know this already, and that you have some other problem, I just don't know what it is.
It might also help to be more precise when using the word "class". You say "the class holding the data". Sorry, a class cannot hold data. An instance of a class, i.e. an object can hold data, but not the class itself...
René Brunner
Forum posts: 364
"On two occasions I have been asked (by members of Parliament!): 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question".
Charles Babbage
Forum posts: 137
Thanx to Mr. rbrunner for your suggestions::
I have changed the previous approach of writing to same stream from 2 different places.
Now I am using 2 different streams.
The code now works fine.........
In the previous case, I got erors on the linethat I have commented
Ttest3FileManager iFileStore;
if(iFileStore) //.............................................................this causes compiler error
{
------
--------
}
I found it strange to be getting errors there!!!!!!!!
The code ran fine when I replaced "iFileStore" with "ETrue"
Then I thought that there must be some special usage with "TClasses"
ANY WAY I HAVE CHANGED MY APPROACH ALTOGETHER AND NOW CODE RUNS FINE!!!
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X SPECIAL THANX TO MR BUTTINGTON FOR HIS COMMENTS!!!!!!!!!!!!!!!!!!!!!!!!!!!! X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Forum posts: 137
Ok,
Mr.rb runner , I read your postings again
and remembered
"such testing can be used with pointer variables only."
I got my error.
Ttest3FileManager iFileStore;
If I declare it as
Ttest3FileManager* iFileStore;
the if statement runs.
I have also got another error in the file where I am storing data.
The file is stored with multiple names like......................
settings.txt
settings.txtsettings.txt
..........................................................................
I ve found the cause of this also,
I used the code
_LIT(KSettingsFile, "settings.txt");
void Ctest3AppUi::CreateDialog()
{
User::LeaveIfError(iEikonEnv->FsSession().CreatePrivatePath(EDriveC));
User::LeaveIfError(iEikonEnv->FsSession().SetSessionToPrivate(EDriveC));
iSettingsFile.Append(KSettingsFile);
InternalizeKSettingsFileToTtest3FileManagerL();
if(Ctest3dialog::RunDlgLD(this,iFileStore))
{
ExternalizeKSettingsFileToTtest3FileManagerL();
};
}
Now I incuded another 2 lines
_LIT(KNULL,"");
iSettingsFile=KNULL;
and the new code is like this............................
_LIT(KNULL,"");
_LIT(KSettingsFile, "settings.txt");
void Ctest3AppUi::CreateDialog()
{
User::LeaveIfError(iEikonEnv->FsSession().CreatePrivatePath(EDriveC));
User::LeaveIfError(iEikonEnv->FsSession().SetSessionToPrivate(EDriveC));
iSettingsFile.Append(KSettingsFile);
InternalizeKSettingsFileToTtest3FileManagerL();
if(Ctest3dialog::RunDlgLD(this,iFileStore))
{
ExternalizeKSettingsFileToTtest3FileManagerL();
};
iSettingsFile=KNULL;
}
Now i get only one file named "settings.txt"
Now I am trying with the previous approach.......................
Think it should work........
Thanks to every one
Forum posts: 137
the previous approach is working!!!!!!!!!!!!!
and this approach is better because it requires less streams and files
AND SO LESS MEMORY