Solved

Create TADOQuery

Posted on 2006-06-17
3
3,456 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month5 days, 11 hours left to enroll

626 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