|
Hi, I'm currently using Borland C++ Builder 6.0 right, and since I'm still a beginner in using this tool, I find many difficulties in using this tool...
I wanted to make multiple forms that could communicate with each other, but I still can't make it...
It's probably a silly question, but I'm trying to get the input from the pop-up window and display it at the main window... But I still can't figure the right way to do it... I wrote the program like the following (Note : Form1 is the main window, and Form2 is the pop-up window)
Where, form1 has 2 button, which is btnInput(to show the pop-up window) and btnClose (to close the application), meanwhile form2 has 2 button, which is btnOK (to retrieve the input and close the pop-up window) and btnCancel (just close the pop-up window)
//---------------------------------------------------------------------------
#include <vcl.h>;
#pragma hdrstop
#include "Main.h"
#include "PopUp.cpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TForm2 *Form2;
String input;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnInputClick(TObject *Sender)
{
Form2->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnCloseClick(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::btnOKClick(TObject *Sender)
{
input = Form2->Edit1->Text;
Form1->lblInput->Caption = input;
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::btnCancelClick(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
Is there anyone who could help, pleaseee...
|
|
|
|
|
|
Hello all
I want to develop application to communicate my pc and my office pc.
In this application, on My office PC i have made one application for listening on Socket for connection.
Now how can i develop an application for my home PC so that i con connect to my office PC?
One think i see on internet is that it is possible with VPN, But its to hard process.
So i want to know any other alternative for it.
Is there anybody who can solve my Problem?
Thanks in advance.
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
Hello everyone,
I am looking for a good sample about how to implement C++ pre-condition and post condition check, but can not find a good sample code. Do you have any referred ones?
Since I can not find, I wrote the patterns in two ways, I am not sure which is correct and if both are not correct, how to implement this pattern?
Sample code 1,
#define MAX 1024
class Base
{
public:
void foo(int i)
{
if (i > MAX)
{
}
else
{
do_foo(i);
}
}
private:
virtual void do_foo(int i) = 0;
};
class Derived : public Base
{
private:
virtual void do_foo(int i)
{
}
};
int main()
{
Derived d;
d.foo (1000);
return 0;
}
Sample 2,
#define MAX 1024
class Base
{
public:
void foo(int i)
{
if (i > MAX)
{
}
else
{
do_foo(i);
}
}
private:
virtual void do_foo(int i) = 0;
};
class Derived : public Base
{
public:
virtual void do_foo(int i)
{
foo (i);
}
};
int main()
{
Derived d;
d.do_foo (1000);
return 0;
}
thanks in advance,
George
|
|
|
|
|
A word of advice not related to your problem: dump the macros! Use an enum instead, for example. One disadvantge of using macros is that they don't have scope and so can't be put into namespace and such.
enum { MAX = 1024 };
Steve
modified on Monday, March 17, 2008 1:49 AM
|
|
|
|
|
Thanks Steve,
My bad, any comments or replies to my original question?
regards,
George
|
|
|
|
|
I prefer the first; why make do_foo public ? This seems to go against the pattern being used.
Steve
|
|
|
|
|
Thanks Steve,
1.
Stephen Hewitt wrote: against the pattern
You mean template method pattern? or something which hides implementation details?
2.
Do you have some more formal examples about pre and post condition implementation in C++? The samples I wrote are by myself. I want to learn some formal ones.
regards,
George
|
|
|
|
|
|
Thanks Steve,
I do not think it contains a sample of pre and post conditions and it only mentions the term pre and post condition check. I have read this article before.
If I am wrong, please feel free to correct me and point out the sample you refer in this article.
regards,
George
|
|
|
|
|
The pre and post checks would obviously be specific to the function and the interface "contract".
Steve
|
|
|
|
|
Thanks Steve,
My question is more about the pattern of pre- and post- condition check. Not about how to do a specific implementation. I have performend some search, but failed to find any definition.
Any recommended resources?
regards,
George
|
|
|
|
|
It is not public. Or did he just cheat changing it without notice?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
It's public in class Derived in the second example.
Steve
|
|
|
|
|
You're right, I was blind .
But we were both more than blind, because second example is completely wrong (recursive madness).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Well, if I state it is a precondition then I don't check it (i.e. I may check it in Debug build, not in Release one).
BTW approach (1) is possibly better because it frees Derived class methods from implementing checking logic (I mean, using approach (2) you must remember to call foo(i) and this is not good expecially if Derived class developer is not the same person who designed Base class).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks CPallini,
Do you have some formal samples about pre- and post- condition pattern simple POC implementation? I have performed some search but can not find relevant stuff. Or you think my implementation is good enough.
Any ideas or recommendations?
regards,
George
|
|
|
|
|
No, I haven't.
I still stand in my original opinion: if I state a precondition then I haven't to check it.
Anyway, I like your first approach.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks CPallini,
With your agreement on my 1st approach of implementation, I think I am confident enough.
regards,
George
|
|
|
|
|
See here[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
So, you prefer implementation 1, I think, right, CPallini?
regards,
George
|
|
|
|
|
|
Thanks CPallini,
Can you let me know what is the bug please?
regards,
George
|
|
|
|
|
OK, I do the exercise for you...
int main()
{
Derived d;
d.do_foo (1000);
return 0;
}
in the above code you need to change d.do_foo(1000); to d.foo(1000); to avoid recursion. BTW if you followed Stephen Hewitt's suggestion, declaring private the Derived class do_foo member, then the compiler was able to stop you from committing recursion madness (it's called OOP nemesis).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks CPallini,
You are correct. My bad. Actually, I have not tested it comprehensively. I just show my ideas about what the pattern looks like.
1.
So, if I fix the bug, you think both could be called pre- and post- condition pattern?
2.
If yes, what do you think the pros and cons of each implementation?
regards,
George
|
|
|
|