Recent

Author Topic: Lazarus string Insert error  (Read 10042 times)

JD

  • Hero Member
  • *****
  • Posts: 1848
Lazarus string Insert error
« on: March 16, 2010, 11:49:55 pm »
Hi there everyone,

I keep getting the error "Wrong number of parameters" on this line of code

Insert('<< Name >>' , strFieldIsEmptyError, 10);

where strFieldISEmptyError := 'The field cannot be empty';

I did some snooping & I found that the compiler looks in db.pas for the definition on the string insert command assuming that I want to insert a record into a table.

I changed the line to
Code: [Select]
System.Insert('<< Name >>' , strFieldIsEmptyError, 10);and then to
Code: [Select]
UTF8Insert('<< Name >>' , strFieldIsEmptyError, 10);and both times I got an error saying "Variable identifier expected".

The code works in Delphi so I'd like to know the Lazarus equivalent for the Delphi string Insert procedure.

Thanks a lot
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

Leledumbo

  • Hero Member
  • *****
  • Posts: 8770
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Lazarus string Insert error
« Reply #1 on: March 17, 2010, 04:24:34 am »
Here's the documentation of System's Insert. What is the type of strFieldISEmptyError? If it's a constant or property, then definitely a compile error would come.

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: Lazarus string Insert error
« Reply #2 on: March 17, 2010, 09:15:37 am »
Here's the documentation of System's Insert. What is the type of strFieldISEmptyError? If it's a constant or property, then definitely a compile error would come.

strFieldISEmptyError is a resourcestring. That may be the problem. I'll try the code with an ordinary string variable.
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

Leledumbo

  • Hero Member
  • *****
  • Posts: 8770
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Lazarus string Insert error
« Reply #3 on: March 17, 2010, 10:20:25 am »
Quote
strFieldISEmptyError is a resourcestring. That may be the problem.
Aha, so that's it. A resourcestring is actually a constant instead of a variable. Since Insert modifies its parameter, you can't use pass resourcestring to it.

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: Lazarus string Insert error
« Reply #4 on: March 17, 2010, 01:25:55 pm »
Quote
strFieldISEmptyError is a resourcestring. That may be the problem.
Aha, so that's it. A resourcestring is actually a constant instead of a variable. Since Insert modifies its parameter, you can't use pass resourcestring to it.

I changed the code to

Code: [Select]
      strErrorString := strFieldIsEmptyError;
      UTF8Insert('<< First Name >>', strErrorString, 10);
      MessageError(Self, strDataEntryError, strErrorString);

Thanks for the tip.  :D
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

 

TinyPortal © 2005-2018