I like to keep all my SQL in a few datamodules and don't spread them
around in all forms. I have made a datamodule containing a
TQuery-component and a TDatasource-component. The TQuery have a default
SQL-statement which I want to use in a DBGrid and at design time I see
the records but when I run the program it's all blank.
What obvious things am I missing?
TIA
Kjell Hansen
Are you auto creating the data module, or creating at run time? If the DM
doesn't exist you'll get an empty grid.
Could you be closing the Query during start up or any other time and then
not reopening?
You could try adding a Query.Open to your DataModule Create handler. See
what that does.
--
John Elrick
jo...@improgrammer.com
www.improgrammer.com
Delphi Application/Component Development
Delphi Mentoring
Kjell Hansen <kjell....@telia.com> wrote in message
news:377918A8...@telia.com...
Do you get any error messages when you run the program? Is it possible that
the DataSource component's DataSet property is being set to nil in your
code?
Bill
--
Bill Todd - TeamB
(TeamB cannot respond to email questions. To contact me
for any other reason remove nospam from my address.)
This is the code of the ShowList form....
unit frmShowListU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, ComCtrls, ToolWin, Db, DBTables, Grids, DBGrids;
type
TfrmShowList = class(TForm)
grdMedlemslista: TDBGrid;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
implementation
uses modMembersListU;
var
oMembersList : TmodMembersListU;
ds :TDataSource;
procedure TfrmShowList.FormCreate(Sender: TObject);
begin
oMembersList := TmodMembersListU.Create(self);
oMembersList.qMembersList.Active := True;
ds := TDataSource.Create(Self);
ds.DataSet := oMembersList.qMembersList;
grdMembersList.DataSource := ds;
end;
procedure TfrmVisaLista.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
ds.Free;
oMembersList.Free;
Action := caFree;
end;
end.
Any suggestions, anyone?
Regards
/Kjell
Try using your designtime datasource instead and see if it works properly.
Although, I have to admit I haven't caught any obvious errors in your code.
John Elrick
Kjell Hansen <kjell....@telia.com> wrote in message
news:377A6227...@telia.com...
/Kjell
TIA
/Kjell
>1. The Active property is True at design time (I can see the grid values)
>2. The module's not auto created (I think it's a waste creating a dozen modules
>and maybe not use them)
If you see the data at design time while Active is true, it must be
that the datamodule is referenced like 'modMembersListU' (the
datamodule's class name without 'T'). This is global variable that
Delphi automatically adds for referencing autocreated
forms/datamodules.
So a possible solution is to create the datamodule before the form and
assign the resulting object to the global variable 'modMembersListU'.
>3. On opening the ShowList I get TDataSource class not found
Where exactly? What is the exact error message?
Jan
Perhaps it would help if you could explain specifically the intention of
this section of your application.
John
Kjell Hansen <kjell....@telia.com> wrote in message
news:377A6792...@telia.com...
> > > 1. The Active property is True at design time (I can see the grid
values)
> > > 2. The module's not auto created (I think it's a waste creating a
dozen
> > modules
> > > and maybe not use them)
> > > 3. On opening the ShowList I get TDataSource class not found
> > >
Regards
/kjell
The Error message appears just before the MDI-child is shown and after I've had to
type the password for the database alias. And it says "Class TDataSource not found"
with the Red-and-white-Critical-error-cross and an "OK" button.
Somehow the program won't continue to function so I have to Ctrl+F2 to close it.
I'm really appreciating the time you're taking to help. Hopefully I will contribute
when I get more knowledge.
Regards
Kjell
Jan Sprengers wrote:
> On Wed, 30 Jun 1999 20:29:59 +0200, Kjell Hansen
> <kjell....@telia.com> wrote:
>
> >1. The Active property is True at design time (I can see the grid values)
> >2. The module's not auto created (I think it's a waste creating a dozen modules
> >and maybe not use them)
>
> If you see the data at design time while Active is true, it must be
> that the datamodule is referenced like 'modMembersListU' (the
> datamodule's class name without 'T'). This is global variable that
> Delphi automatically adds for referencing autocreated
> forms/datamodules.
> So a possible solution is to create the datamodule before the form and
> assign the resulting object to the global variable 'modMembersListU'.
>
> >3. On opening the ShowList I get TDataSource class not found
>
It seems to me you could use this:
Kjell Hansen <kjell....@telia.com> wrote in message
news:3780E1F5...@telia.com...
I can understand what you are attempting to display - but I still am
confused as to why you are creating the DataSource at runtime? Or how the
creation of the dropdown affects the creation of the DataSource? Your
answer doesn't address these questions.
It seems to me you could use this:
unit frmShowListU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms,
Dialogs,
StdCtrls, ComCtrls, ToolWin, Db, DBTables, Grids, DBGrids;
type
TfrmShowList = class(TForm)
grdMedlemslista: TDBGrid;
ds : TDataSource; << Declared at design time
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action:
TCloseAction);
implementation
uses modMembersListU;
var
oMembersList : TmodMembersListU;
procedure TfrmShowList.FormCreate(Sender: TObject);
begin
oMembersList := TmodMembersListU.Create(self);
oMembersList.qMembersList.Active := True;
ds.DataSet := oMembersList.qMembersList;
end;
procedure TfrmVisaLista.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
oMembersList.Free;
Action := caFree;
end;
end.
and eliminate the dynamic creation. I only say this because the approach
you've taken implies you may be doing other things which could be affecting
your form. Plus, you've stated you can "see" the data at design time which
means your grid is already attached to a datasource, yet your form
declaration doesn't show one and you seem to not be able to use it at
runtime. So I ask again, why specifically are you creating a datasource at
runtime?
John
>Your ideas makes sense to me, but...Being the beginner I am... How?
>It's a MDI-program where I'm opening the DBgrid-form as a child.
If it is an MDI application, it probably doesn't make much sense what
I said about assigning the created datamodule to the global variable
(except as a test case).
Since MDI programs typically allow a window to be open more than once,
you can't rely on global variables for referencing. The approach you
took by dynamically creating the datamodule is good, but you should
probably assign it to a variable of the form's class, not another
(static) global variable.
>The Error message appears just before the MDI-child is shown and after I've had to
>type the password for the database alias. And it says "Class TDataSource not found"
>with the Red-and-white-Critical-error-cross and an "OK" button.
Where is your TDataSource located at design time? On the form or the
datamodule? Check if it has a corresponding variable in the published
part of the form/datamodule. If it is missing, delete the component
and recreate it.
HTH,
Jan
The dropdowncombo isn't implemented yet, but I hope I can use the same
Datasource. I'm planning on calling a function in the datamodule which returns
a TStringList to fill the combo and changing the year in the combo will trigger
an event where I re-read the grid with the selected year instead of the
current.
I'm still puzzled, though, if this is the right approach. The question is if
it's applyable for larger multiusers database applications? This is the first
thing I'm doing in Delphi and it's a single user application but the next step
will probably be for multiple users and I like to do things the scalable way :)
Any advices are greatly appreciated.
Again, many thanx, especially to you, John.
Regards
Kjell Hansen
Good luck and let me know if you have any more questions.
John
Kjell Hansen <kjell....@telia.com> wrote in message
news:37810D8E...@telia.com...