Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create TADOQuery

Posted on 2006-06-17
3
Medium Priority
?
3,512 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

963 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