Recent

Author Topic: [SOLVED]Illegal Identifier error  (Read 2033 times)

WilliamAndrade

  • New member
  • *
  • Posts: 7
[SOLVED]Illegal Identifier error
« on: February 12, 2018, 09:07:02 pm »
Hello guys i've strugling with a error that is named "Illegal Qualifier" i see another topic here with that error http://forum.lazarus.freepascal.org/index.php?topic=17201.0 but dont seen to be my case, the line highlighted is:
Code: Pascal  [Select][+][-]
  1. Label1.Caption:=LblTitulo.Caption.Substring(19);
in the call of "Substring"

Here is the code:
Code: Pascal  [Select][+][-]
  1. var
  2.   FrmCadAtvComercio: TFrmCadAtvComercio;
  3.  
  4. implementation
  5.  
  6. {$R *.lfm}
  7.  
  8. { TFrmCadAtvComercio }
  9.  
  10. procedure TFrmCadAtvComercio.FormCreate(Sender: TObject);
  11. begin
  12.   Control:=TControlCadComercio.Create;
  13. end;
  14.  
  15. procedure TFrmCadAtvComercio.FormShow(Sender: TObject);
  16. begin
  17.   //LblTitulo.Caption:=LblTitulo.Caption+'.'+Control.ProxVersaoComercio; Descomentar após o cadastro da tabela primária
  18.   LblTitulo.Caption:=LblTitulo.Caption+'.'+'1';
  19. end;
  20.  
  21. procedure TFrmCadAtvComercio.BotaoCadastrarClick(Sender: TObject);
  22. var
  23.   Linha:Integer;
  24.   Coluna:Integer;
  25.   AtvComercio:array[0..9] of String;
  26. begin
  27.   //Control.InserirAtv(LblTitulo.Caption.Substring(19));//Cadastrando Atividade no banco
  28.  
  29.   Label1.Caption:=LblTitulo.Caption.Substring(19);
  30.  
  31.   for Linha:=0 to 5 do
  32.   begin
  33.  
  34.     for Coluna:=0 to 9 do
  35.     begin
  36.        AtvComercio[Coluna]:=StrGrid.Cells[Linha,Coluna];
  37.     end;
  38.      //Control.InserirAtvComercio();
  39.   end;
  40.  
  41. end;
  42.  
  43. end.
  44.  

Sorry for any english errors, any help is appreciated. Thanks for the attention.
« Last Edit: February 12, 2018, 10:35:55 pm by WilliamAndrade »

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: Illegal Identifier error
« Reply #1 on: February 12, 2018, 10:13:12 pm »
Code: Pascal  [Select][+][-]
  1. Label1.Caption:=LblTitulo.Caption.Substring(19);
Unfortunately Caption is not of string type, but of TCaption, and SubString is defined as TStringHelper.Substring, i.e. only for "pure" strings. So, practically, you can't use SubString with captions, you should use copy instead (it has a bit different syntax) or convert the caption to string like
Code: Pascal  [Select][+][-]
  1. SomeString := LblTitulo.Caption;
  2. Label1.Caption := SomeString.Substring(19);
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Bart

  • Hero Member
  • *****
  • Posts: 5538
    • Bart en Mariska's Webstek
Re: Illegal Identifier error
« Reply #2 on: February 12, 2018, 10:13:21 pm »
Code: Pascal  [Select][+][-]
  1. type
  2.   TCaption = TTranslateString;
  3. ...
  4.   TTranslateString = type String;

The consequence of this construct is that stringhelpers do not apply to TCaption.

Bart

Edit: Eugene beat me by 9 seconds  >:D

Thaddy

  • Hero Member
  • *****
  • Posts: 16653
  • Kallstadt seems a good place to evict Trump to.
Re: Illegal Identifier error
« Reply #3 on: February 12, 2018, 10:23:59 pm »
Code: Pascal  [Select][+][-]
  1. type
  2.   TCaption = TTranslateString;
  3. ...
  4.   TTranslateString = type String;

The consequence of this construct is that stringhelpers do not apply to TCaption.

Bart

Edit: Eugene beat me by 9 seconds  >:D
I removed my previous reply, but isn that a consequence of UTF8 in Lazarus vs sysutils using Ansi for typehelpers?
But I am sure they don't want the Trumps back...

WilliamAndrade

  • New member
  • *
  • Posts: 7
Re: Illegal Identifier error
« Reply #4 on: February 12, 2018, 10:35:21 pm »
Thanks for the answers! you guys rocks! good question Thaddy but i'm out of time to give a try anyway i have tried the Eugene sugestion and worked :) (sorry for any english errors) Thanks Eugene ^^

 

TinyPortal © 2005-2018