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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATA MODULE 1

Status
Not open for further replies.

gmie

Programmer
Sep 6, 2001
29
0
0
MY
Hello guys..

I need help to transfer TTable and TDataSource from form to Data Module. This is my code to generete item into TCombobox:=

procedure TForm1.FormCreate(Sender: TObject);
begin

while not TableCountry1.Eof do
begin
combobox1.Items.Add(TableCountry1.FieldByName('description').AsString);
tablecountry1.Next;
end;
end;

this can work properly when TTable and TDataSource placed on TForm1.

So can anybody modified this code in order TTable and TDataSource is place on Data Module.

Please help me.

TQ
 
Firstly,

You must include you data module in the uses

for example....
uses
DataMod1;

Where DataMod1 is you filename (without .pas)

Now you can refence your data module object, so your code would look like

procedure TForm1.FormCreate(Sender: TObject);
begin

with datamodule1
while not TableCountry1.Eof do
begin
combobox1.Items.Add(TableCountry1.FieldByName('description').AsString);
tablecountry1.Next;
end;
end;

or

procedure TForm1.FormCreate(Sender: TObject);
begin

while not Datamodule1.TableCountry1.Eof do
begin
combobox1.Items.Add(Datamodule1.TableCountry1.FieldByName('description').AsString);
DateModule1.tablecountry1.Next;
end;
end;
 
ok schu...let me try first then I shout to U back.... :D
 
For :
uses
DataMod1;

Where I should place it?...... after interface or implementation..?

Then can U give me reasons why we should placed there...
 
Use the Ide, go to File --> Use Unit, Delphi takes care of the rest.

Regards S. van Els
SAvanEls@cq-link.sr
 
ok. this is my modified code:=

while not Datamodule1.tablecountry.Eof do
begin
combobox1.Items.Add(Datamodule1.tablecountry.fieldbyname('description').AsString);
Datamodule1.tablecountry.Next;
end;
end;

but there are an error as bellow:=

Debugger Exception Notification: Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0048A44 in module 'Project1.exe'. Read of address 00000058'.

What should I do now?. Or maybe there are any changes in Object Inspector..?
 
...and Delphi highlight this line :=

while not Datamodule1.tablecountry.Eof do


 
Ensure that your datamodule is part of the project, if not: Project (Menu) - Add to project - select the filename of your data module

If it is part of your project already then it is probably just not being created:
If you go into Project - Options - Forms(tab) - ensure your datamodule is listed under Auto-create forms

Hopefully that will sort you out.
 
Thanks guys.

It work properly now.

TQ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top