Thread: Update a Value From TEdit

Update a Value From TEdit

From
Bob Pawley
Date:
I am attempting to update a table using a value that is displayed on a TEdit component. I am getting an access violation error.
 
Can someone tell me what I am doing wrong??
 
procedure TLoopBuilderForm.NewLoopButtonClick(Sender: TObject);

  var Edit1 : TEdit ;

begin
  
 
       PSQLQuery1.Close;{close the query}
      //assign new SQL expression Monitor
      PSQLQuery1.SQL.Clear;
      PSQLQuery1.SQL.Add ('Update P_ID.Loops');
      PSQLQuery1.SQL.Add ('Set IDW_Loop_ID = + LoopNumberEdit');
      PSQLQuery1.SQL.Add ('Where P_ID.Loops.Loop_Name = :Loop_Name');
      PSQLQuery1.ParamByName('LoopNumberEdit').Value := Edit1.Text;
      PSQLQuery1.Execsql;
 
end;
 
Running Delphi 6 and PostgreSQL 8.2 on Win XP.
 
Bob

Re: Update a Value From TEdit

From
Raymond O'Donnell
Date:
On 13/04/2007 19:05, Bob Pawley wrote:

> I am attempting to update a table using a value that
> is displayed on a TEdit component. I am getting an
> access violation error.

Hi Bob,

An access violation error means that some part of your code is trying to
access memory that it shouldn't. It most likely means that you're trying
to use a component that hasn't yet been created, so it's a bug in your
code rather than a problem with PostgreSQL.

>        PSQLQuery1.Close;{close the query}
>       //assign new SQL expression Monitor
>       PSQLQuery1.SQL.Clear;
>       PSQLQuery1.SQL.Add ('Update P_ID.Loops');
>       PSQLQuery1.SQL.Add ('Set IDW_Loop_ID = + LoopNumberEdit');
>       PSQLQuery1.SQL.Add ('Where P_ID.Loops.Loop_Name = :Loop_Name');
>       PSQLQuery1.ParamByName('LoopNumberEdit').Value := Edit1.Text;
>       PSQLQuery1.Execsql;

How do you create PSQLQuery1? - Did you drop it on the form at
design-time, or have you created it on-the-fly in your code? If the
latter, then that's probably your problem - have you called
PSQLQuery1.Create() somewhere before the code above executes?

However, if PSQLQuery1 was created at design time, then the problem lies
elsewhere. Look for some component which you've declared, but whose
constructor you haven't invoked.

BTW, from the code above it seems you're passing in an integer value to
the query; I prefer to use ParamByName().AsInteger as an extra layer of
safety, to ensure that an integer acyually does get passed in.

Ray.

---------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
---------------------------------------------------------------


Re: Update a Value From TEdit

From
Raymond O'Donnell
Date:
On 13/04/2007 19:25, Raymond O'Donnell wrote:

>> PSQLQuery1.SQL.Add ('Where P_ID.Loops.Loop_Name = :Loop_Name');
>> PSQLQuery1.ParamByName('LoopNumberEdit').Value := Edit1.Text;

I meant to say also that the parameter name you're passing to the
ParamByName() function isn't the same as the one you've specified in the
query.

Ray.

---------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
---------------------------------------------------------------

Re: Update a Value From TEdit

From
"Arthur Hoogervorst"
Date:
Hi:

What's the point of  declaring the TEdit locally? Use a string
instead. Additionally, in Delphi [and any other OOP language) if you
want to use objects, you instantiate them first, as in  Edit1 :=
TEdit.Create(nil);


Regards,


Arthur



On 4/13/07, Bob Pawley <rjpawley@shaw.ca> wrote:
>
>
> I am attempting to update a table using a value that is displayed on a TEdit
> component. I am getting an access violation error.
>
> Can someone tell me what I am doing wrong??
>
> procedure TLoopBuilderForm.NewLoopButtonClick(Sender:
> TObject);
>
>   var Edit1 : TEdit ;
>
> begin
>
>
>        PSQLQuery1.Close;{close the query}
>       //assign new SQL expression Monitor
>       PSQLQuery1.SQL.Clear;
>       PSQLQuery1.SQL.Add ('Update P_ID.Loops');
>       PSQLQuery1.SQL.Add ('Set IDW_Loop_ID = + LoopNumberEdit');
>       PSQLQuery1.SQL.Add ('Where P_ID.Loops.Loop_Name = :Loop_Name');
>       PSQLQuery1.ParamByName('LoopNumberEdit').Value := Edit1.Text;
>       PSQLQuery1.Execsql;
>
> end;
>
> Running Delphi 6 and PostgreSQL 8.2 on Win XP.
>
> Bob