Solved

TStrings Access Violation

Posted on 2002-03-22
3
356 Views
Last Modified: 2010-04-05
Hi Experts!!
I get an Access Violation when I call the Clear method of my TStrings object:

procedure TFServeis.ExecutaSQL(sentencia: String);
var
 s: TStrings;
begin
 s.Clear;  //Exception!!
 s.Append(sentencia);
 ExecutaSQL(s);
end;

As u c, the code is pretty simple, what I'm doing wrong?
Here are the declarations:

type
 TFServeis = class(TForm)
 private
  { Private declarations }
 public
  { Public declarations }
  function Cerca(Sentencia,Camp: String):Variant;
  procedure ExecutaSQL(sentencia: TStrings); overload;
  procedure ExecutaSQL(sentencia: String); overload;
 end;

0
Comment
Question by:Kurtis
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
jsweby earned 50 total points
ID: 6888356
This is because you have declared a variable object of type TStrings, but you have not instantiated the object yet. What you need to do is create s first, then use it:

var
   s: TStringList;
begin
   s := TStringList.Create;
   Try
   s.Clear;
   s.Append(sentencia);  
   ExecutaSQL(s);

   Finally
   s.Free;
   End; {Try..Finally}
end;

J.
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6888358
This is because you have declared a variable object of type TStrings, but you have not instantiated the object yet. What you need to do is create s first, then use it:

var
   s: TStringList;
begin
   s := TStringList.Create;
   Try
   s.Clear;
   s.Append(sentencia);  
   ExecutaSQL(s);

   Finally
   s.Free;
   End; {Try..Finally}
end;

J.
0
 

Author Comment

by:Kurtis
ID: 6888384
Thanks jsweby, your answer was just perfect and quick, you have helped me a lot!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

13 Experts available now in Live!

Get 1:1 Help Now