Avatar of hidrau
hidrauFlag for Brazil

asked on 

I need a help to Chang the value of a field in the setText event

Hello Guys

I have a dbgrid linked to an adoquery

My first field is a text that gets a prod codi, like this:  ' 9T5086'


I have a table named ChangeCodeNew, this table has two main field.

OldCode and NewCode

After entering the code in my column,  I need to seek this code in that table.
 If the code is in the table I need to change it to new code.
My question is:

Is the event setText suitble to do this once that my code needs to be changed after entering it.

With my code I notice that after replacing the oldcode to newcold, the function is called again,
making another seeking in my table.

I appreciated any clue
thanks
procedure TFItensnovos.Q_Produtoanalisepro_codiSetText(Sender: TField; const Text: String);
Var
  Sit, newcode : string;
begin
  prodnovo := text
  With Dtm_BaseDados1.wwQ_DePara do begin
     Close;
     SQL.Clear;
     SQL.Add('Select * from SIAPDPA');
     SQL.Add('Where PDP_PANT = '+''''+newcode +'''');
     Open;
  End;
 
  If Dtm_BaseDados1.wwQ_DePara.RecordCount > 0 Then Begin
     newcode := Dtm_BaseDados1.wwQ_DePara.FieldByName('PDP_PNOV').AsString;
     MessageDlg('Produto "' + Text + '" é o código antigo do produto.' + Chr(13) + 'It will be replaced by current code. [ ' + newcode + ' ]', MtInformation, [mbOK], 0);
     Q_Produtoanalisepro_codi.AsString := newcode ;
  End;
End;

Open in new window

Delphi

Avatar of undefined
Last Comment
Geert G
Avatar of kretzschmar
kretzschmar
Flag of Germany image

i would use the onValidate-event instead . . .

meikl ;-)
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of hidrau
hidrau
Flag of Brazil image

ASKER

Hello Geert_Gruwez,
Is this also valid for MS SQL 2000 and Access ?
Thanks very much for your explanation about bind variable.

It was wonderful and I will split point with you

Hi kretzschmar, I am having problem to replace the value of my field. When I do this I call again my code :((

I made an sample so that you can help me doing what I need. Please, download it from this link
http://www.hidrautorque.com.br/arquivo/sample.zip
Thanks
Avatar of hidrau
hidrau
Flag of Brazil image

ASKER

  Hello Geert_Gruwez,

 Should I use a parameter for ''S'' once it doesn't change the value or I can go on this way with my query?

   Q_AUX.SQL.clear ;
   Q_AUX.Sql.Add('select PRO_CODI From SIAPROD (NOLOCK)');
   Q_AUX.Sql.Add(' where PRO_CODI =:P1');
   Q_AUX.Sql.Add('and (PRO_EXCL <>''S'' or PRO_EXCL is null)');
   Q_aux.Parameters.ParamByName('P1').Value := Q_maqitensItAnalise_codi.AsString;
   Q_AUX.Open;

Thanks
SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of hidrau
hidrau
Flag of Brazil image

ASKER

Thanks very much guys for the help
Avatar of Geert G
Geert G
Flag of Belgium image

you should use bind variables as much as possible for changing values

if you use constants in your query, there will not be much difference
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo