Solved

Create TADOQuery

Posted on 2006-06-17
3
3,435 Views
Last Modified: 2007-12-19
hi
i'm using Delphi 7 with SQL Server 2000
i have a problem with TADOQuery,
i wanna create some ADOQuery in a form and set each of them to a variable of TADOQuery, but i get error on run time , my error is it "access violation at address......"

//*** this procedure is in a  F_DModule (MODULE FORM)*******
procedure CreateADOQuery(var SQuery : TADOQuery;SDataSource :TDataSource;QString : String);
begin
  SQuery := TADOQuery.Create(nil);
  SQuery.Connection := F_DModule.ADO_TOOSKA;  
  SQuery.Close;
  SQuery.SQL.Clear;
  SQuery.SQL.Text := QString;
  SQuery.Open;
  SDataSource := TDataSource.Create(nil);
  SDataSource.DataSet := SQuery;
end;

procedure TF_Phone_Call.FormActivate(Sender: TObject);
var Qry1 : TADOQuery;
      DS1 :TDataSource;
begin
  CreateADOQuery(Qry1,DS1,' Select * From Car');
  DBGrid1.DataSource := DS1;      //**** error occur in this line***
end;


what's wrong in the code and what i must do ?


tanxfull
Mahsa
0
Comment
Question by:Mahsa60
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 16927212
your declaration

var Qry1 : TADOQuery;
      DS1 :TDataSource;

is within
procedure TF_Phone_Call.FormActivate(Sender: TObject);
local declared

guess you run ot of scope

define it within your type-declaration or just global

meikl ;-)
0
 
LVL 6

Accepted Solution

by:
Amir Azhdari earned 50 total points
ID: 16928315
hi Mahsa60 ,
try to define the CreateADOQuery's 'SDataSource' parameter with 'VAR' , it mean :


procedure TF_DModule.CreateADOQuery(var SQuery : TADOQuery;VAR SDataSource :TDataSource;QString : String);
begin
  SQuery := TADOQuery.Create(nil);
  SQuery.Connection := F_DModule.ADO_TOOSKA;
  SQuery.Close;
  SQuery.SQL.Clear;
  SQuery.SQL.Text := QString;
  SQuery.Open;
  SDataSource := TDataSource.Create(nil);
  SDataSource.DataSet := SQuery;
end;


Regards
Azhdari
0
 

Author Comment

by:Mahsa60
ID: 16928544
tanx
i wrote VAR for SQuery but i forgot to write VAR for SDataSource
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Correct Component for Shopping Cart. 2 132
Strange behavior when a form is closed 6 75
Adoquery sql  left join does not work 25 118
how to change, disabled button color FMX ? 1 63
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question