samchan
asked on
How to retrieve data from Modal forms
I have for example a unit A that call a modal form in Unit B. In Unit B, items are selected using Multiselect in the DBGrid shown in unit B. What I need is to process the items selected in Unit A after the form in unit B is closed. How to go about it?
SA/\/\
"If you have always done it that way, it is probably wrong."
SA/\/\
"If you have always done it that way, it is probably wrong."
ASKER
I did try that. However, those SelectedRows of ItemDBGrid somehow do not have any values after the ShowModal line! But those SelectedRows are still available if I check it in the Modal Unit.
The codes I am trying is as follows:
begin
with TfrmItemSelection.Create(S elf) do
try
if ShowModal = mrOk then
begin
if ItemDBGrid.SelectedRows.Co unt>0 then
begin
with ItemDBGrid.DataSource.Data Set do
begin
for i:=0 to ItemDBGrid.SelectedRows.Co unt-1 do
begin
GotoBookmark(pointer(ItemD BGrid.Sele ctedRows.I tems[i]));
for j := 0 to FieldCount-1 do
begin
if (j>0) then s:=s+', ';
s:=s+Fields[j].AsString;
end;
Listbox1.Items.Add(s);
s:= '';
end;
end;
end;
end;
finally
Free;
end;
end;
The codes I am trying is as follows:
begin
with TfrmItemSelection.Create(S
try
if ShowModal = mrOk then
begin
if ItemDBGrid.SelectedRows.Co
begin
with ItemDBGrid.DataSource.Data
begin
for i:=0 to ItemDBGrid.SelectedRows.Co
begin
GotoBookmark(pointer(ItemD
for j := 0 to FieldCount-1 do
begin
if (j>0) then s:=s+', ';
s:=s+Fields[j].AsString;
end;
Listbox1.Items.Add(s);
s:= '';
end;
end;
end;
end;
finally
Free;
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yup. You're right. I closed the Dataset.
Thank you.
Hmm... now who should I give the point too.
Thank you.
Hmm... now who should I give the point too.
Go for it kambiz
ASKER
Okay. Then I will give the point to kambiz. However, thanks to you millerw because your example encouraged me to try the solution which i've tried but thought was not working.
No problem.
Good luck and happy coding!
Good luck and happy coding!
Thank you Samchan and thank you Millerw.
With TfrmSaveSearch.Create(Self
try
If ShowModal = mrOK then
begin
FSearch.Save(txtName.Text,
end;
finally
Free;
end;
Scott