Solved

TStrings Access Violation

Posted on 2002-03-22
3
362 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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
code issue 8 156
Unique identifier on a terminal server (rdp) 4 67
Dynamically Created Query 3 62
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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