I have a modalDialog with a W3EditBox where the user enters a string that ultimately gets added to a W3ListBox on the main form
I am trying to prevent the modalDialog from closing if one of these conditions exist
1.) W3EditBox text is nil
2.) if W3EditBox text already exists in the W3ListBox list
Here is the code for calling the dialog form (has just a label, edit box, and ok and cancel buttons)
procedure TfrmMain.HandleAddClick(Sender: TObject);
begin
Application.ShowModal('frmGoal', 'W3Panel1', 'edtTitle', InitDialog, OkResponse, nil);
end;
Here is the code for handling the OK response
procedure TfrmMain.OkResponse(AForm: TW3CustomForm);
begin
//code here to prevent if title is nil or already exists in listbox
W3Listbox1.Add(TfrmGoal(AForm).Title);
end;
On another note, I don’t understand how the W3ListBox’s IndexOf method works. I am use to search for a string – and it looks like it wants a control
Thanks
Shane
Let's say we have a visual project with main form
MainFormand dialogAddDialog. The main form contains a listboxlbItemsand the dialog contains a wrapper panelW3Panel1with three child objects - an edit boxinpItemand two buttons -btnOKandbtnCancel. The AddDialog dialog is registered with a nameAddDialog.The dialog is then displayed with a simple
ShowModalcall.The simplest way to access the main form's listbox from the dialog is to provide the dialog with the reference to the main form's component. To do so, add a property to the dialog
and then assign its value in the
InitDialog.In the dialog itself you can then set up button click handlers.
The
CloseDialogmethod will check whether the edit box is empty or equal to an already existing item in the listbox. You are correct that the IndexOf method is of no use in this case so just use aforloop to check all listbox items.BTW, the best way to access the dialog edit box from the main form is to expose it via a property in the dialog object:
The code in the main program can then access this property.