Board index » cppbuilder » child windows not closing and listbox not clearing

child windows not closing and listbox not clearing

i'm having a rather confusing problem try to close a child window. it has a
cancel button that does the following

void __fastcall TSettings_Form::Cancel_ButtonClick(TObject *Sender)
{
 Settings_Form->Close();

Quote
}

but the window doesn't close, it just sits there. however, if i click on x
the window does close. this happens for every window apart from the main
one. is there anything that could stop the window from closing?

similarly i'm having a problem clearing listboxes. the listbox box shows a
list of servers from a paradox file. its only a TListBox so i have a
function to clear the listbox and re-add all the servers into it. code
follows....

void __fastcall TSettings_Form::UpdateServersListBox(void)
{
 Servers_ListBox->Clear();

 Data->Servers_DataSource->DataSet->First();
 while (!Data->Servers_DataSource->DataSet->Eof) {
     ShowMessage("updating " +
Data->Servers_DataSource->DataSet->FieldByName("ServerAddress")->Value);

Servers_ListBox->AddItem(Data->Servers_DataSource->DataSet->FieldByName("Ser
verAddress")->Value, NULL);
     Data->Servers_DataSource->DataSet->Next();
 }

Quote
}

its shows a message for all the right servers, but the listbox doesn't in
the first place so if i delete one or edit a name it doesn't show a message
for it but its still in the list because it didn't clear in the first place.

i'm using bcb6 prof 10.166 on win98se. any help would be appreciated.

 

Re:child windows not closing and listbox not clearing


Quote
"mostuff" <do...@emailback.com> wrote in message

news:3eb99ab8@newsgroups.borland.com...

Quote
> void __fastcall TSettings_Form::Cancel_ButtonClick(TObject *Sender)
> {
>  Settings_Form->Close();
> }

You don't need to use the global pointer since you're already inside the
form.  Just use the implicit 'this' pointer instead:

    void __fastcall TSettings_Form::Cancel_ButtonClick(TObject *Sender)
    {
        Close();
        // or
        // this->Close();
    }

Quote
> but the window doesn't close, it just sits there. However,
> if i click on x the window does close. this happens for
> every window apart from the main one. is there anything
> that could stop the window from closing?

Do you have any OnCloseQuery or OnClose event handlers for the forms?
Clicking the "X" simply calls Close() internally.

Quote

Servers_ListBox->AddItem(Data->Servers_DataSource->DataSet->FieldByName("Ser

Quote
> verAddress")->Value, NULL);

AddItem() is not a method of TListBox, or any other native VCL component,
for that matter.  That suggests that either 1) you hand-typed the code in
your message instead of copy/pasting it from your actual project, or else 2)
you're not actually using the native TListBox component as you say you are.
If #1, then please always copy/paste your actual code, don't hand-type it
manually, its too prone to introducing other errors that are not in the
actual code, and only serves to confuse people.

Quote
> its shows a message for all the right servers, but the
> listbox doesn't in the first place

Doesn't what in the first place?  I think you left out an important word in
there.

Quote
> so if i delete one or edit a name it doesn't show a
> message for it

Why would it?  If you have code that is supposed to display such a message,
you didn't include it in your post here.  Your code here is only adding
entries, it is not editing or removing them individually.

Gambit

Re:child windows not closing and listbox not clearing


"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3eb9a7d4$1@newsgroups.borland.com...

Quote

> "mostuff" <do...@emailback.com> wrote in message
> news:3eb99ab8@newsgroups.borland.com...

> > void __fastcall TSettings_Form::Cancel_ButtonClick(TObject *Sender)
> > {
> >  Settings_Form->Close();
> > }

> You don't need to use the global pointer since you're already inside the
> form.  Just use the implicit 'this' pointer instead:

>     void __fastcall TSettings_Form::Cancel_ButtonClick(TObject *Sender)
>     {
>         Close();
>         // or
>         // this->Close();
>     }

that worked -  i'll remember it for the future, thanks.

Quote

Servers_ListBox->AddItem(Data->Servers_DataSource->DataSet->FieldByName("Ser

Quote
> > verAddress")->Value, NULL);

> AddItem() is not a method of TListBox, or any other native VCL component,
> for that matter.  That suggests that either 1) you hand-typed the code in
> your message instead of copy/pasting it from your actual project, or else
2)
> you're not actually using the native TListBox component as you say you
are.
> If #1, then please always copy/paste your actual code, don't hand-type it
> manually, its too prone to introducing other errors that are not in the
> actual code, and only serves to confuse people.

ummm.....i copied and pasted it. from the code....

TListBox *Servers_ListBox;

and from bcb6vcl.hlp.....

Derived from
TCustomListBox
    AddItem

and then.......

 VCL Reference
TCustomListBox::AddItem

TCustomListBoxTCustomListBox See also
---------------------------------------------
Adds an item to the list box

void __fastcall AddItem(AnsiString Item, TObject AObject);

Description
Call AddItem to add a new item to the end of the list.
Item is the text of the item to add.
AObject is the object associated with the new item.

Quote
> > its shows a message for all the right servers, but the
> > listbox doesn't in the first place

> Doesn't what in the first place?  I think you left out an important word
in
> there.

clear, sorry.

Quote
> > so if i delete one or edit a name it doesn't show a
> > message for it

> Why would it?  If you have code that is supposed to display such a
message,
> you didn't include it in your post here.  Your code here is only adding
> entries, it is not editing or removing them individually.

this is for the delete button

void __fastcall TSettings_Form::Delete_ButtonClick(TObject *Sender)
{
 if (Servers_ListBox->ItemIndex > -1) {
    TMsgDlgBtn Response = MessageDlg("Are you sure you want to delete " +
Servers_ListBox->Items->Strings[Servers_ListBox->ItemIndex] + "?",
mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0);
    if (Response == mrYes) {
       TLocateOptions Options;
       if (Data->Servers_DataSource->DataSet->Locate("ServerName",
Servers_ListBox->Items->Strings[Servers_ListBox->ItemIndex], Options)) {
          Data->Servers_DataSource->DataSet->Delete();
          Settings_Form->UpdateServersListBox();
       }
    }
 }

Quote
}

it deletes the record from the paradox file but because Clear() doesn't
clear in UpdateServersListBox() it stays in the list.

thanks for the reply, looking forward to the next one.

Re:child windows not closing and listbox not clearing


Quote
"mostuff" <do...@emailback.com> wrote in message

news:3eb9cb79@newsgroups.borland.com...

Quote
> from bcb6vcl.hlp.....

> Derived from
> TCustomListBox
>     AddItem

Hmm.  Yet another new feature added in BCB6 that I haven't run across yet.

Quote
>           Data->Servers_DataSource->DataSet->Delete();
>           Settings_Form->UpdateServersListBox();

Why are you reloading the entire list just to update a single item?  You
already have the exact index of the item to remove, you could just remove it
directly:

    Servers_ListBox->Items->Delete(Servers_ListBox->ItemIndex);

Quote
> it deletes the record from the paradox file but because
> Clear() doesn't clear in UpdateServersListBox() it stays
> in the list.

Do you, by chance, have the ListBox's Style property set to one of the
lbVirtual... values?  If so, then Clear() has no effect for those particular
styles.  In which case, you need to set the Count property to 0 instead of
calling Clear().

Gambit

Re:child windows not closing and listbox not clearing


"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3eb9ce08$1@newsgroups.borland.com...

Quote

> "mostuff" <do...@emailback.com> wrote in message
> news:3eb9cb79@newsgroups.borland.com...

> > from bcb6vcl.hlp.....

> > Derived from
> > TCustomListBox
> >     AddItem

> Hmm.  Yet another new feature added in BCB6 that I haven't run across yet.

get used to it, it pops up everywhere ;-)

Quote
> >           Data->Servers_DataSource->DataSet->Delete();
> >           Settings_Form->UpdateServersListBox();

> Why are you reloading the entire list just to update a single item?  You
> already have the exact index of the item to remove, you could just remove
it
> directly:

>     Servers_ListBox->Items->Delete(Servers_ListBox->ItemIndex);

that's what i did when i originally wrote it but then i thought in the
interests of
code reuse i'd use UpdateServersListBox() (it hasn't ocurred to me since
then
to use the first method).

Quote
> > it deletes the record from the paradox file but because
> > Clear() doesn't clear in UpdateServersListBox() it stays
> > in the list.

> Do you, by chance, have the ListBox's Style property set to one of the
> lbVirtual... values?  If so, then Clear() has no effect for those
particular
> styles.  In which case, you need to set the Count property to 0 instead of
> calling Clear().

thats what i thought too, but no, style is lbStandard. here's the code from
the dfm file

object Servers_ListBox: TListBox
      Left = 6
      Top = 16
      Width = 134
      Height = 127
      AutoComplete = False
      ExtendedSelect = False
      ItemHeight = 13
      Sorted = True
      TabOrder = 0
    end

Other Threads