Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: sethjackson on October 05, 2005, 01:09:55 am

Title: Using wxTextCtrl::Remove()
Post by: sethjackson on October 05, 2005, 01:09:55 am
I'm trying to implement a delete function for this text editor I'm making (I'm doing this to learn about wxWidgets).
I want to have a delete function that works like notepad's. :) Basically if there is text selected and the user clicks Edit->Delete the
text editor deletes the text.
Anyways, Here is the code; it doesn't do anything.

Code
void MainFrame::OnEditDelete(wxCommandEvent& event)
{
long int *begin, *end;

m_pTextCtrl->GetSelection(begin, end);

m_pTextCtrl->Remove((long int)begin, (long int)end);
}

I haven't posted the relevant event table entries or anything but it should be easy to understand.
I want to know if this is the correct way to do this. I'm assuming its not since it doesn't work.
Title: Re: Using wxTextCtrl::Remove()
Post by: mandrav on October 05, 2005, 08:49:51 am
I'm trying to implement a delete function for this text editor I'm making (I'm doing this to learn about wxWidgets).
I want to have a delete function that works like notepad's. :) Basically if there is text selected and the user clicks Edit->Delete the
text editor deletes the text.
Anyways, Here is the code; it doesn't do anything.

Code
void MainFrame::OnEditDelete(wxCommandEvent& event)
{
long int *begin, *end;

m_pTextCtrl->GetSelection(begin, end);

m_pTextCtrl->Remove((long int)begin, (long int)end);
}

I haven't posted the relevant event table entries or anything but it should be easy to understand.
I want to know if this is the correct way to do this. I'm assuming its not since it doesn't work.

Your code is wrong. You have declared two pointer to ints that point nowhere (garbage).
Try this:

Code
void MainFrame::OnEditDelete(wxCommandEvent& event)
{
long int begin, end;

m_pTextCtrl->GetSelection(&begin, &end);

m_pTextCtrl->Remove(begin, end);
}
Title: Re: Using wxTextCtrl::Remove()
Post by: sethjackson on October 05, 2005, 06:36:29 pm
DOH, DOH, DOH.  :oops:

Am I an idiot or what?

Thanks Yiannis.