Solved

Create TADOQuery

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now