Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBGrid problem

Status
Not open for further replies.

MLNorton

Programmer
Nov 15, 2009
134
US
I am creating a very simple program in Delphi 2007. I have two forms, Main and Display. Man contains two buttons, Next and Close. Next contains the following code.
Application.CreateForm(TForm_Display,Form_Display);
Form_Display.ShowModal;
Form_Display.Free;
Form Main also contains an ADOConnection, ADOTable and a DataSource.
Form Main had Display in its Uses clause and Display has Main in its Uses clause.
Form is displayed and it only contains a DBgrid.
Problem:
There is no listing in the DBGrid DataSource property.
What is my problem and what is the solution?
 
A dbgrid's datasource property can be set at design time, and run time. Simply having the other unit in the uses clause does not associate a db aware component with a datasource. Since Display has Main's unit in its uses clause, it will be able to see the datasource on Main that is associated with the table. If you want to set it at runtime, do so in Display's FormCreate method otherwise, simply set it to the datasource within the object inspector for the dbgrid.

Also, to create your form, you should wrap the create within a try..finally block to ensure the memory associated with the form is freed.

Code:
var
   MyDisplayForm: TForm_Display
begin
   MyDisplayForm := TForm_Display.Create;
   try
      MyDisplayForm.ShowModal;
   finally
      MyDisplayForm.Free;
   end;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top