Recent

Author Topic: ¿Como se usan los StringHelpers ?  (Read 3815 times)

mav

  • Jr. Member
  • **
  • Posts: 80
¿Como se usan los StringHelpers ?
« on: June 26, 2021, 07:31:22 am »
Hola, he estado probando helpers diversos y...he conseguido  :D :D muchos errores :
 
Code: Pascal  [Select][+][-]
  1.          procedure TForm1.Button1Click(Sender: TObject);
  2.             begin
  3.                 //if Edit1.Text.IsNullOrEmpty then        //-->Error: Illegal qualifier
  4.  
  5.                  if Edit1.Text.IsNullOrWhiteSpace then     //--> Error: Illegal qualifier
  6.                    begin
  7.                      ShowMessage('...es null o vacio');
  8.                     end;
  9.            end;                                      
  Saludos.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: ¿Como se usan los StringHelpers ?
« Reply #1 on: June 26, 2021, 07:44:43 am »
Probablemente porque TEdit.Text no es (en sentido estricto) una string sino a TCaption ... que es una TTranslateString ... que es:
Code: Pascal  [Select][+][-]
  1. type TTranslateString = type string;
así que es mayormente compatible con strings normales pero no exactamente el mismo tipo.

Para poder usar el StringHelper tendrás que pasarlo a una cadena:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var sv: String;
  3. begin
  4.   sv := Edit1.Text;
  5.   if sv.IsNullOrWhiteSpace then
  6.   begin
  7.     ShowMessage('...es null o vacio');
  8.   end;
  9. end;
« Last Edit: June 26, 2021, 07:50:07 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

mav

  • Jr. Member
  • **
  • Posts: 80
Re: ¿Como se usan los StringHelpers ?
« Reply #2 on: June 26, 2021, 08:07:14 am »
 También había probado pasándole una variable string (por si acaso...) y  mas formas, pero no he conseguido que funcione en ninguna :
Code: Pascal  [Select][+][-]
  1.         procedure TForm1.Button1Click(Sender: TObject);
  2.         var
  3.           sv: String;
  4.           begin
  5.              sv := Edit1.Text;
  6.              if sv.IsNullOrWhiteSpace then
  7.                begin
  8.                ShowMessage('...es null o vacio');
  9.               end;
  10.       end;
  11.  
  12.      {Compile Project, Mode: Release, Target: project1.exe: Exit code 1, Errors: 2
  13.        unit1.pas(33,9) Error: Wrong number of parameters specified for call to "IsNullOrWhiteSpace"
  14.          syshelp.inc(313,30) Error: Found declaration: class IsNullOrWhiteSpace(const AnsiString):Boolean; Static;
  15.      }
  16.  

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: ¿Como se usan los StringHelpers ?
« Reply #3 on: June 26, 2021, 09:07:21 am »
No me había dado cuenta: son métodos de "clase". Inténtalo así:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var sv: String;
  3. begin
  4.   { Igual funciona también con:
  5.   if TStringHelper.IsNullOrWhiteSpace(Edit1.Text) then ...
  6.   pero por si acaso ...}
  7.   sv := Edit1.Text;
  8.   if TStringHelper.IsNullOrWhiteSpace(sv) then
  9.   begin
  10.     ShowMessage('...es null o vacio');
  11.   end;
  12. end;
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

mav

  • Jr. Member
  • **
  • Posts: 80
Re: ¿Como se usan los StringHelpers ?
« Reply #4 on: June 26, 2021, 09:25:27 am »
...también lo había intentado de esa forma y el error es en ese caso:
 
Compile Project, Mode: Release, Target: project1.exe: Exit code 1, Errors: 1
unit1.pas(36,19) Error: Objective-C categories and Object Pascal class helpers cannot be used as types

 ...

mav

  • Jr. Member
  • **
  • Posts: 80
Re: ¿Como se usan los StringHelpers ?
« Reply #5 on: June 26, 2021, 09:30:42 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2.  
  3. var sv: String;
  4. begin
  5.  //Igual funciona también con:
  6.   if TStringHelper.IsNullOrWhiteSpace(Edit1.Text) then
  7.  // pero por si acaso ...}
  8.   //sv := Edit1.Text;
  9.  { if TStringHelper.IsNullOrWhiteSpace(sv) then }
  10.   begin
  11.     ShowMessage('...es null o vacio');
  12.   end;
  13. end;
  14.  
  15. end.
  16.           {Compile Project, Mode: Release, Target: project1.exe: Exit code 1, Errors: 1, Hints: 1
  17. unit1.pas(30,5) Note: Local variable "sv" is assigned but never used
  18. unit1.pas(33,19) Error: Objective-C categories and Object Pascal class helpers cannot be used as types
  19. }
  20.                                                      
  21.  
« Last Edit: June 26, 2021, 09:32:25 am by mav »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: ¿Como se usan los StringHelpers ?
« Reply #6 on: June 26, 2021, 09:41:12 am »
Eso es muy raro. No estarás en modo MACPAS o algo parecido ¿no? En modo OBJPAS o DELPHI debería funcionar sin más.

Quizá tengas que mostrar algo más de código o incluso adjuntar el proyecto completo.


Vale, no me hagas caso; soy yo el que ha metido la pata :-[

Hay que usar un tipo "real", como en:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   if String.IsNullOrWhiteSpace(Edit1.Text) then
  4.   begin
  5.     ShowMessage('...es null o vacio');
  6.   end;
  7. end;
Así sí que funciona. Debería probar las cosas antes de hablar ... %)
« Last Edit: June 26, 2021, 09:46:20 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

mav

  • Jr. Member
  • **
  • Posts: 80
Re: ¿Como se usan los StringHelpers ?
« Reply #7 on: June 26, 2021, 10:20:35 am »
 :) :)Bien! Correcto, así es como funciona...ya puedo usar mas helpers.
Gracias.
  Saludos

 

TinyPortal © 2005-2018