Board index » cppbuilder » I think this might be closer to what I want

I think this might be closer to what I want


2003-07-31 04:07:52 AM
cppbuilder76
When I tried your code suggestions for creation of the DatePicker(Form) and
assigning a parent to the DatePicker(Form), the component box was blank when
it was dropped onto a TForm.
However, I now have thought to add the DatePicker->Show line of code, making
the DateCal component code look like this:
__fastcall TDateCal::TDateCal(TComponent* Owner)
: TWinControl(Owner)
{
Height = 21;
Width = 120;
TDatePicker *DatePicker = new TDatePicker(this);
DatePicker->Parent = this;
DatePicker->Show();
}
When I built this and then dropped the DateCal component onto a TForm, an
error message dialog came up: "Control " has no parent window."
I'm not sure to what it is referring, but it seems like all I have to do is
define this parent window and then it might work.
Do you know how this might be done?
 
 

Re:I think this might be closer to what I want

Eric wrote:
Quote
__fastcall TDateCal::TDateCal(TComponent* Owner)
: TWinControl(Owner)
{
...
TDatePicker *DatePicker = new TDatePicker(this);
That should be:
DatePicker = new TDatePicker(this);
// TDatePicker *DatePicker; in __published:
Quote
DatePicker->Parent = this;
DatePicker->Show();
}

When I built this and then dropped the DateCal component onto a TForm, an
error message dialog came up: "Control " has no parent window."
Did someting similar with a new component derived from TPanel.
class TMyPanel : public TPanel
In the constructor a TEdit and a TLabel are created as also
a form with:
Form = new TForm ( this ); //TFoem *Form; in __published:
Form->Caption = " This is a TForm";
Form->Parent = this;
Form->Show();
During designtime in bcb3 the Tedit and TLabel are shown
but not the TForm; When I run the app the TForm is seen with
the TitleBar. The TForm is restricted to the TMyPanel.
Quote
I'm not sure to what it is referring, but it seems like all I have to do is
define this parent window and then it might work.

Do you know how this might be done?
I do not understand why yo get the error message because what would
be the difference between your and my form ?
Which version of builder do you use ?
But: I do not understand at all that you make a new component
and create a derivative of a TForm in is constructor solely to
grab a TEdit from it. Why are not you providing TDateCall with
those Edit's ?
Hans.
 

Re:I think this might be closer to what I want

Quote
But: I do not understand at all that you make a new component
and create a derivative of a TForm in is constructor solely to
grab a TEdit from it. Why are not you providing TDateCall with
those Edit's ?
That is actually what I wasn't sure how to do in the first place, but now
I've figured it out, based on your suggestions. I found that I didn't need a
form at all. Here's what I did:
__fastcall TDateCal::TDateCal(TComponent* Owner)
: TWinControl(Owner)
{
Height = 21;
Width = 120;
Edit1 = new TEdit(this);
Edit1->Left = 0;
Edit1->Top = 0;
Edit1->Width = 97;
Edit1->Height = 21;
Edit1->Parent = this;
Edit2 = new TEdit(this);
Edit2->Left = 97;
Edit2->Top = 0;
Edit2->Width = 23;
Edit2->Height = 21;
Edit2->Parent = this;
BitBtn1 = new TBitBtn(this);
BitBtn1->Left = 99;
BitBtn1->Top = 2;
BitBtn1->Width = 19;
BitBtn1->Height = 18;
BitBtn1->Glyph->LoadFromFile("C:\\Program
Files\\Borland\\CBuilder6\\Projects\\Calendar Component\\cal.bmp");
BitBtn1->Hint = "Open Calendar";
BitBtn1->ShowHint = true;
BitBtn1->Parent = this;
dtt = dtt.CurrentDate();
//accesses current date and stores information in dtt
currentStrDate = DateToStr(dtt);
//stores current date in string in mm/dd/yyyy format
Edit1->Text = currentStrDate;
}
And I also have these in __published:
TEdit *Edit1;
TEdit *Edit2;
TBitBtn *BitBtn1;
So now when I drop the component onto a new form, everything comes up fine
AND the TEdits and TBitBtn can't receive focus at design time like before.
Now I have that other Finalize/destructor problem, which I'm going to add to
after I post this message.
Thanks for all your help!
Eric
 

{smallsort}