Board index » delphi » Reassign DB Aware Controls??

Reassign DB Aware Controls??


2006-02-06 12:02:36 PM
delphi220
I'm trying to pass a TADODataset *reference* to a modal window,
like this:
*** In Parent Form:
Placed a TADODataSet VCL component (BatchOptimistic)
*** In Modal Form:
Placed a TADODataSet VCL component (BatchOptimistic)
Also placed a TDataSource VCL component for DB aware controls
Here's the code to call the modal Form:
*****
MyParentDataset.Close;
MyParentDataset.Parameters.ParamByName('ID').Value = 99;
MyParentDataset.Open;
MyModalWindow := TMyModalWindow.Create(Self);
MyModalWindow.MyModalDataset := MyParentDataset;
MyModalWindow.ShowModal;
*****
I put the following code in Modal Form:
ShowMessage(MyModalDataset.FieldByName('ID').AsString);
The message box shows the ID value correctly, but the data does
not show in the DB aware controls in the modal form..! What's
wrong here???
I read somewhere about reassigning dataset to db aware controls.
I have no idea what this means. Please give me some sample
code!
 
 

Re:Reassign DB Aware Controls??

Michelle Brennan writes:
Quote

I'm trying to pass a TADODataset reference to a modal window,
like this:

*** In Parent Form:
Placed a TADODataSet VCL component (BatchOptimistic)

*** In Modal Form:
Placed a TADODataSet VCL component (BatchOptimistic)
Also placed a TDataSource VCL component for DB aware controls


Here's the code to call the modal Form:
*****
MyParentDataset.Close;
MyParentDataset.Parameters.ParamByName('ID').Value = 99;
MyParentDataset.Open;

MyModalWindow := TMyModalWindow.Create(Self);
MyModalWindow.MyModalDataset := MyParentDataset;
MyModalWindow.ShowModal;
*****


I put the following code in Modal Form:
ShowMessage(MyModalDataset.FieldByName('ID').AsString);

The message box shows the ID value correctly, but the data does
not show in the DB aware controls in the modal form..! What's
wrong here???

I read somewhere about reassigning dataset to db aware controls.
I have no idea what this means. Please give me some sample
code!
I am not really sure why you need to use 2 datasets but this sounds to
me as a circular reference problem, i.e., a form referencing another
form that also references the first.
Just a question, have you tried to use a DataModule? I think it would
help you much and also separate better presentation from data processes.
I would do following:
1- Create a DataModule. Add the necessary Datasets and DataSources to
it. Put NO Dataset or DataSource in any other form.
2- Reference the DataModule from your Modal Form (and any form that
needs access to db)
3- Assign DataSets to DataSources.
4- Assign the DataSource to your db-aware component
Any method that makes operations on the Datasets should be implemented
in the DataModule. This way, if you have a problem you will always know
where to look instead of going over all implied units.
Good luck
--
Best regards :)
Guillem Vicens Meier
Dep. Informatica Green Service S.A.
www.clubgreenoasis.com
 

Re:Reassign DB Aware Controls??

"Michelle Brennan" <XXXX@XXXXX.COM>сообщи?сообщила ?новостях
следующе? news:43e6d86c$XXXX@XXXXX.COM...
Quote

I'm trying to pass a TADODataset *reference* to a modal window,
like this:

*** In Parent Form:
Placed a TADODataSet VCL component (BatchOptimistic)

*** In Modal Form:
Placed a TADODataSet VCL component (BatchOptimistic)
Also placed a TDataSource VCL component for DB aware controls


Here's the code to call the modal Form:
*****
MyParentDataset.Close;
MyParentDataset.Parameters.ParamByName('ID').Value = 99;
MyParentDataset.Open;

MyModalWindow := TMyModalWindow.Create(Self);
MyModalWindow.MyModalDataset := MyParentDataset;
MyModalWindow.ShowModal;
*****


I put the following code in Modal Form:
ShowMessage(MyModalDataset.FieldByName('ID').AsString);

The message box shows the ID value correctly, but the data does
not show in the DB aware controls in the modal form..! What's
wrong here???

I read somewhere about reassigning dataset to db aware controls.
I have no idea what this means. Please give me some sample
code!
This is how it should look like:
MyParentDataset.Parameters.ParamByName('ID').Value = 99;
MyParentDataset.Requery;
MyModalWindow := TMyModalWindow.Create(Self);
MyModalWindow.MyModalDataSource.DataSet := MyParentDataset;
MyModalWindow.ShowModal;
And 2 more suggestions:
1. Get rid out of MyModalDataset since you don't need it
2. Read some book on Delphi
 

Re:Reassign DB Aware Controls??

"Michelle Brennan" <XXXX@XXXXX.COM>writes
Quote

I'm trying to pass a TADODataset *reference* to a modal window,
like this:
What I'd do is...{code is off the top of my head, so there are probably
syntax errors}
{Modal form}
public
Execute(DataSet :TDataSet) :Boolean;
end;
TMyModalForm.Execute(DataSet :TDataSet):Boolean;
begin
{Check to see if we should show the modal form}
if (DataSet.IsEmpty) then
begin
{if the dataset is empty, don't show the form}
ShowMessage('No data, no modal form for you!!!');
end
else
begin
{set the modal form's TDataSource component}
dsData.DataSet := DataSet;
Result := (ShowModal = mrOK);
end
end;
{now, the main form}
{Some button click}
var
MMF :TMyModalForm;
begin
MMF := TMyModalForm.Create(nil);
try
if MMF.Execute(MyDataModule.MyADODataSet) then
begin
{update a label, etc}
end;
finally
MMF.Release;
end;
end;
 

Re:Reassign DB Aware Controls??

Problem solved!!! Thanks!!!
"Vitali Kalinin" <XXXX@XXXXX.COM>writes:
Quote

This is how it should look like:

MyParentDataset.Parameters.ParamByName('ID').Value = 99;
MyParentDataset.Requery;
MyModalWindow := TMyModalWindow.Create(Self);
MyModalWindow.MyModalDataSource.DataSet := MyParentDataset;
MyModalWindow.ShowModal;

And 2 more suggestions:
1. Get rid out of MyModalDataset since you don't need it
2. Read some book on Delphi