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

x
?
Solved

TStrings Access Violation

Posted on 2002-03-22
3
Medium Priority
?
369 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 200 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

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

783 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