|
I'm not sure that I understand your question. You have a class, CYourClass, and in that class you have a memeber variable, ChangedDates, that is an array of two dates, right? Like this:
class CYourClass
{
public:
COleDateTime ChangedDates[2];
....
};
And you have a member function that assigns some values to this array:
void CYourClass::AssignValues()
{
ChangedDates[0] = date1;
ChangedDates[1] = date2;
}
Now you want to calculate how many periods of length dt there is between ChangedDates[0] and ChangedDates[1], right? And you're asking if you can access ChangedDates directly or if you need a new array of COleDateTimes? If this is the case, then the answer is that you can access ChangedDates directly, either from a member function or from outside CYourClass (since it's a public member):
int CYourClass::CalcDifference(period dt)
{
int iDifference = 0;
COleDateTime date = ChangedDates[0];
for (int i=0; ChangedDates[1]>date; i++) {
iDifference++;
date += dt;
}
return iDifference;
}
int CSomeOtherClass::CalcDifference(CYourClass yourclass, period dt)
{
int iDifference = 0;
COleDateTime date = yourclass.ChangedDates[0];
for (int i=0; yourclass.ChangedDates[1]>date; i++) {
iDifference++;
date += dt;
}
return iDifference;
}
If you use ChangedDates from inside a member function you can use it directly. If it is used from outside CYourClass you have to qualify it with the name of the CYourClass instance.
hope this was what you asked for
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
In fact you understand my question, but perhaps i have some problem to understand how it works. But, in my case i need to use the ChangedDates in the same class it is defined, but if i use it to calculate the number of period; if i just call it ChangedDates[0]..., do you think i could get the right value i need?
thanks
gerald
|
|
|
|
|
Hmmm... I don't get it. Could you explain in more detail what you want to do?
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Ok, after i have posted it, i saw that i din't explain very well what i want to do. (perhaps because my english is far to be fluent!)
so i will try to give you an example.
As we saw above, in the .h i declare:
CMyClass
{
protected:
COleDateTime ChangedDates[2];
.
.
.
}
In .cpp:
Firstly i create a function which modify the dates, and affetc to ChangedDates, some new dates as you showed me before.
Now, i want to calculate number of period.
int CMyClass::CalcNumberOfPeriod(COleDateTime StartDate,COleDateTime EndDate)
{
int iNumberOfPeriod;
//the 2 dates i have in this function have to be modified, so i call the first function(which could be called ModifyDates). It's this thing which borrow me, because i don't know if i have to do a declartion like that:
COleDateTime ChangedDatesBis[2];
ChangedDatesBis=ModifyDates(StartDate,EndDate);
//And after i could use ChangedDatesBis, by calcuylating, for example, the difference between ChangedDatesBis[1] and ChangedDatesBis[0].
.
.
.
return iNumberOfPeriod;
}
i hope that this post would be more explicit
gerald
|
|
|
|
|
Since I'm from Denmark, English is not my native language either. Unfortunately my French is even worse than my English
Anyway, I'm still a little bit puzzled. What does your ModifyDates function do? Does it just assign the date argument to the protected member array like this:
COleDateTime[] CMyClass::ModifyDates(COleDateTime date1, COleDateTime date2)
{
ChangedDates[0] = date1;
ChangedDates[1] = date2;
return ChangedDates;
}
If so, then your CalcNumberOfPeriod function could look like this
int CMyClass::CalcNumberOfPeriod(COleDateTime StartDate,COleDateTime EndDate)
{
int iNumberOfPeriod;
ModifyDates(StartDate,EndDate);
.
.
.
return iNumberOfPeriod;
}
Is this what you wanted?
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
the function ModifyDates doesn't assign only 2 dates, it takes Startdate and EndDate, and modify them if, for example, the day of EndDate is not the same that StartDate, so i change the day and put the new date in ChangedDate[1].
So, even if it's not the same thing you show me, the kind of calculation in ModifyDates are the same. After, i have created this function, i need to know how many period could i find between 2 dates, and this dates need to be modified before we calculate the number of period, so i need to call the function ModifyDates inside CalcNumberOfPeriod.
So, are you sure i just have to call the function ModifyDates, without declare a new variable?
|
|
|
|
|
Ahh, let me see if I get this correct.
You have two dates, StartDate and EndDate. You want to calculate how many periods there is between the two dates, but first you have to modify the two dates in some way. When you have calculated the number of periods you don't need the modified dates anymore. Right?
If so, I would forget all about member variables. Do it this way:
void CMyClass::ModifyDates(COleDateTime* pDates)
{
}
int CMyClass::CalcNumberOfPeriod(COleDateTime StartDate COleDateTime EndDate, periodtype dt)
{
COleDateTime Dates[2];
Dates[0] = StartDate;
Dates[1] = EndDate;
ModifyDates(Dates);
int iPeriods;
iPeriods = .....
return iPeriods;
}
Of course, the modified dates are lost when CalcNumberOfPeriod returns as the Dates array is automatic.
Now I can also see why you wanted to allocate the dates in your first posts. One way to do the above using heap allocated objects could be:
COleDateTime* CMyClass::AllocAndModifyDates(COleDateTime date1, COleDateTime date2)
{
COleDateTime* pDates = new COleDateTime[2];
pDates[0] = date1;
pDatse[1] = date2;
return pDates;
}
int CMyClass::CalcNumberOfPeriod(COleDateTime StartDate, COleDateTime EndDate, periodtype dt)
{
COleDateTime* pDates = AllocAndModifyDates(StartDate, EndDate);
int iPeriods;
delete[] pDates;
return iPeriods;
}
Hope I got it right this time.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I was sure that at one moment we could understand what exactly each of us mean, so, i believe that your last post is exactly what i would do. I will try it, and if you are agree, i will send you an email to tell you if it works
thanks a lot for your help
gerald
|
|
|
|
|
Please do.
Good luck.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Another question, if i do that:
COleDateTime *Date=new COleDateTime[2];
Date[0]=StartDate;
Date[1]=EndDate;
return Date;
delete[] Date;
in the same function, do you think that it's right, because i do that, and when i try to debug, i could see the allocation of my pointer in the debug window. But there is a pb, only the Date[0]=StartDate is considered or seem to be considered. Could you help me?
thanks
gerald
|
|
|
|
|
Well, in your above code snippet the line
delete[] Date;
never gets called, because you do a return in the line above. Result: Memory leak. See my other reply on how to keep the Date pointer "alive" across function calls.
As to your question: You're right, you can only see Date[0], but that's because the Variables window only knows that Date is a pointer to _a_ COleDateTime object, not to an array of objects. If you in your watch window types Date[1] you'll se that it's there.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
i have a probleam on passing the value between two while statement and here i give the sample probleam::
//////////////////////////////////////////////
int i=0;
int j=0;
int k=0;
if(.....)
m_pSet->MoveFirst();
{
while(i<10)
{i++;
j++
//statement
}//end while
}//end if
if(.....)
{
m_pSet->Move(j);
while(k<20)
{
k++;
//statement
}//end while
}//end if
////////////////////////////////////////////////
so how can i pass the value j from the first "if" statement to the second "if" statement?
or u all got some other matter that can use please let me know thank to u all.
|
|
|
|
|
What's the problem ? Do you want to pass each value of j in ? You'll need to nest your statements. I take it this is a contrived example ( i will always equal j ), but as they all stay in scope, I don't see what the problem is unless you need to nest the commands to use every value of j in your second loop.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
|
while(i<10)
{
while(j<10)
{
}
}
Can I recommend you buy Stroustrup ?
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
It's hard to tell exactly what you're doing, but I think you meant something more along the lines of:
while(i<10)
{
//statement
if( /*something to do with j */ )
{
m_pSet->Move(j);
while(k<20)
{
//statement
}
}
}
But I can't tell without a better idea of what you're trying to do. Hopefully though you can see it better now that some people have shown you some more ways to nest things.
Regards,
John
|
|
|
|
|
I have a function
int GetSize(void *a_pPointer)
{
<code>
}
How can I do it ???
thanks.
|
|
|
|
|
It is not possible in standard C/C++, but see Microsoft-specific _msize in malloc.h . Note that values returned by this function might be slightly rounded up in CRT release mode when the sizes are small.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I am trying to create a CCommandBarCtrl control, however
it isn't in the traditional sense (as the wizard does it).
I am not creating it in a top-level window, I am creating
a command bar as a child of a child window itself; and it
doesn't really seem to work. It will draw the top-level
menus on the toolbar, however clicking them does nothing.
None of the menus pop up, or anything.
Its creation pretty much goes like this:
m_hMenu = LoadMenu(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDM_MENUBAND));
m_cmdbar.AttachMenu(m_hMenu);
m_cmdbar.LoadImages(IDR_TOOLBAR);
...which is in essence exactly the same as the wizard code
does it.
Can someone help?
|
|
|
|
|
How can i handle unexpected exits to the program (i.e. a user hits ctrl+break) so that i can clean up memory allocated? Thanks!
|
|
|
|
|
See signal .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I think this should server your purpose:
BOOL WINAPI ConsoleHandler(DWORD dwCtrlType)
{
switch(dwCtrlType)
{
case CTRL_CLOSE_EVENT:
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
{
// Cleanup code
return TRUE;
}
}
return FALSE;
}
int _tmain( ...)
{
SetConsoleCtrlHandler(ConsoleHandler, TRUE);
//
// Other code goes here
}
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Hi,
I am trying to make a VERSIONABLE_SCHEMA for future versions of a program, but I allways receive '-1' as version number when I call GetObjectSchema() function this is the probe code: (What could be the problem?)
//METEOGRAFICADOC.H
class CMeteoGraficaDoc : public CDocument
{
protected: // create from serialization only
CMeteoGraficaDoc();
DECLARE_SERIAL(CMeteoGraficaDoc)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMeteoGraficaDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMeteoGraficaDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CMeteoGraficaDoc)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//METEOGRAFICADOC.CPP
IMPLEMENT_SERIAL(CMeteoGraficaDoc, CDocument,1| VERSIONABLE_SCHEMA)
// CMeteoGraficaDoc serialization
void CMeteoGraficaDoc::Serialize(CArchive& ar)
{
CDocument::Serialize(ar);
if (ar.IsStoring())
{
ar<<dia<<mes<<anno<<horaactual<<titulo;
}
="" else
="" {
="" int="" nversion="ar.GetObjectSchema();" always="" '-1'
="" ar="">>dia>>mes>>anno>>horaActual>>Titulo;
}
}
NOTE: Where ar< appears, the code is right but I don't know why I cannot look what appears after the first < in The Code Project screen.
|
|
|
|
|
This is a classic problem. MFC serialization versioning works only for CObject-derived objects serialized with a call to one of these functions:
CArchive& operator <<(CArchive & ar, const CObject* pOb);
void CArchive::WriteObject(const CObject* pOb);
They save metadata about object type and version before actual object bits written by Serialize method.
The problem is that CDocument is saved with a direct call to Serialize inside CDocument::OnSaveDocument. There's no metadata about document itself. There may be some metadata about document members if you save them using functions listed above. So if you need a version number at the beginning of MFC-serialized file, write it yourself. It's much easier than rewriting OnSaveDocument (but this option is also possible).
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi I have built this MFC Wizard using the Visual C utility for building Wizards.
all is fine, except for i don't seem to have control over the next and back buttons in terms of enabling and disabling them. I would like to keep them all disbaled until all fields on the dialog are entered. How do I do this , since I can't find the resource id for these buttons?
|
|
|
|