Solved

TStrings Access Violation

Posted on 2002-03-22
3
366 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
[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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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 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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month5 days, 9 hours left to enroll

627 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