Error: Incompatible type for arg no. 1: Got "TStringList, expected AnsiString" lazarus / 16-Databases ---------------------------------------------------------------------- talorigomat · 2014-08-15 16:39 in my program I have set a constant as INSERTSQL 'execute procedure insertorg (:Name, :Level_num, :Parent);' When I try to assign this to the to a TSQLQuery using either the Add or AddText method [eg: Query1.Sql.Add(INSERTSQL);] I receive the error above. How should I make the assignment? ---------------------------------------------------------------------- eny · 2014-08-15 17:10 Better show us the code; this does not tell us anything about the nature of the error. What you typed above should not give an error; but I'm pretty sure your actual code looks different. ---------------------------------------------------------------------- talorigomat · 2014-08-15 21:05 Here is a brief definition of the former to show the declaration of the constant Type   TForm1 = class(TForm)   private     { private declarations }     const       FORMHEIGHT = 530;       PNLWORKTOP = 105;       GRBADDTOP = 142;       INSERTSQL ='execute procedure insertorg (:Name, :Level_Num, :Parent);';      public     { public declarations }   end; Here is  procedure where the error occurs procedure TfrmOrganisation.Button1Click(Sender: TObject); begin   if qryModify.SQL.Text <> INSERTSQL then     begin       with qryModify do         begin           Active:=False; SQL.Clear;           SQL.Add(INSERTSQL);      // <--- point error occurs         end;     end;   with qryModify do   begin     Params.ParamByName('Name').AsString := edtAdd.Text;     case workWith of       'Division':         Params.ParamByName('level_Num').AsSmallInt:= 1;       'Directorate':         begin           Params.ParamByName('level_Num').AsSmallInt:= 2;           Params.ParamByName('Parent').AsLargeInt:= qryTop.FieldValues['OrgId'];         end;       'Specialty':         begin           Params.ParamByName('level_Num').AsSmallInt:= 3;           Params.ParamByName('Parent').AsLargeInt:= qryMiddle.FieldValues['OrgId'];         end;     end;       try         begin           ExecSQL;           edtAdd.Clear;         end;       except         on e :Exception do          ShowMessage(e.Message);       end;     end;  end; ---------------------------------------------------------------------- rvk · 2014-08-15 21:14 Quote from: talorigomat on August 15, 2014, 11:05:23 pmCode: [Select]with qryModify do begin   Active:=False;   SQL.Clear;   SQL.Add(INSERTSQL);      // <--- point error occurs end; Your problem is with the "with qryModify" structure. qryModify also contains a property InsertSQL and that's the same as your constant. (so your not using your constant INSERTSQL in that line but the property InsertSql which is a TStringList) Solution is to rename your INSERTSQL to something else like INSERT_SQL. A constant with the same name as a property is a bad thing and will always lead to trouble. ---------------------------------------------------------------------- Leledumbo · 2014-08-16 04:43 Quote from: rvk on August 15, 2014, 11:14:11 pmqryModify also contains a property InsertSQL and that's the same as your constant. I guess we need a compiler warning for cases like this (and it must be shown in any case, be the code compilable or not, because it's a hint for the coder), with block is sometimes really evil. ---------------------------------------------------------------------- User137 · 2014-08-16 09:37 Code: [Select]SQL.Add(INSERTSQL);      // <--- point error occursIsn't the error a self-explanatory? INSERTSQL is of type TStringList. SQL.Add() expects a string. edit: Oh, you are lucky that it caught it as error though. I wouldn't even be surprised if overloaded function TStringList.Add(sl: TStringlist); existed. ---------------------------------------------------------------------- talorigomat · 2014-08-20 11:23 Thanks for the tip Leledumbo.  I renamed the constant and everything works fine.