Solved

Create TADOQuery

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Communication Between RC4 Delphi <-> PHP 3 123
FMX enumerated colours 2 119
LAN or WAN ? 11 96
Firemonkey DbLookupComboBox equivalent ? 2 56
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…

828 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