0
function TDM1.fct_login(nom_util, mdp_util: string): boolean;
begin
  ADOQuery1.Parameters.ParamByName('@nom_util').AsString = 'John Smith';
  ADOQuery1.Parameters.ParamByName('@mdp_util').AsString = '524462';
  ADOQuery1.ExecSQL;
  Result := ADOQuery1.RecordCount = 1;
end;

An error message pops up saying

undeclared identifier: AsString
error code : E2003

I tried changing it to AsValue, same error!

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Ash
  • 59
  • 6

1 Answers1

3

The error is correct, but not the only error in your code. Change your code to

ADOQuery1.Parameters.ParamByName('@nom_util').Value := 'John Smith';

(the = may just have been a typo, in Delphi's Pascal, the assignment operator is :=, not =.)

Ado parameters do not have an AsString or AsValue property. They are of type TParameter, defined in AdoDB.Pas as

 TParameter = class(TCollectionItem)
  [...]
  public
    procedure Assign(Source: TPersistent); override;
    procedure AppendChunk(Val: OleVariant);
    procedure LoadFromFile(const FileName: string; DataType: TDataType);
    procedure LoadFromStream(Stream: TStream; DataType: TDataType);
    property ParameterObject: _Parameter read GetParameter;
    property Parameters: TParameters read GetParameters;
    property Properties: Properties read GetProperties;
  published
    property Name: WideString read GetName write SetName;
    property Attributes: TParameterAttributes read GetAttributes write SetAttributes default [];
    property DataType: TDataType read GetDataType write SetDataType default ftUnknown;
    property Direction: TParameterDirection read GetParameterDirection write SetParameterDirection default pdInput;
    property NumericScale: Byte read GetNumericScale write SetNumericScale default 0;
    property Precision: Byte read GetPrecision write SetPrecision default 0;
    property Size: Integer read GetSize write SetSize default 0;
    property Value: Variant read GetValue write SetValue;
  end;

Update I can tell from your comments that there is a certain amount of confusion. Perhaps this will help:

Suppose you have a Names table with an AName field and you want to find the row with the value 'Me' in the AName field.

The following code will do it:

AdoConnection1.Connected := True;
AdoQuery1.SQL.Text := 'select * from [Names] where AName = :AName';
AdoQuery1.Parameters.ParamByName('AName').Value := 'Me';
AdoQuery1.Open;

In the SQL.Text, :AName is simply a placeholder for the parameter in the query. The convention is that the text following the ':' is the name of the table column, but it doesn't have to be, any valid Sql name will do, as in

AdoQuery1.SQL.Text := 'select * from [Names] where AName = :Something';
AdoQuery1.Parameters.ParamByName('Something').Value := 'Me';
MartynA
  • 30,454
  • 4
  • 32
  • 73
  • I corrected the previous syntaxe mistake ans now another message showed up :"Classe exception EDatabaseError with message 'AdoQuery1 :parameters '@nom_util' not found" – Ash Jul 20 '20 at 14:19
  • Given paarameterised Sql like 'select * from SomeTable where Name = :Name`, the parameter name would be 'Name', not '@Name'. – MartynA Jul 20 '20 at 14:24
  • What about the parameter value, do I define @ or just leave it blank? – Ash Jul 20 '20 at 14:34
  • I don't follow what you mean. If you write the Sql like I quoted it, the placeholder for the parameter isn't a blank, it's the ':Name'. – MartynA Jul 20 '20 at 14:39
  • by that I mean adoQuery/parameters/value, do I leave it blank? – Ash Jul 20 '20 at 14:41
  • I didn't mean parameter/name – Ash Jul 20 '20 at 14:41
  • What is the "it" you are referring to in "do I leave it blank?" – MartynA Jul 20 '20 at 14:51
  • 1
    @Ash read Embarcadero's documentation: [Using Parameters in Queries](http://docwiki.embarcadero.com/RADStudio/en/Using_Parameters_in_Queries) and [Handling Command Parameters](http://docwiki.embarcadero.com/RADStudio/en/Handling_Command_Parameters) – Remy Lebeau Jul 20 '20 at 18:45
  • So, has this answered your q? If not, what difficulty are you still having? – MartynA Jul 23 '20 at 06:57