Solved

TStrings Access Violation

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Magic Software info 18 156
Tidtcpserver listening on multiports? 1 56
DBCtrlGrid, Delphi, Scroll 7 35
Posting a string with PostMessage 23 49
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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