Recent

Author Topic: Re: Error: Operator is not overloaded - (SOLVED)  (Read 7638 times)

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Re: Error: Operator is not overloaded - (SOLVED)
« on: June 25, 2013, 07:50:27 pm »
My goal is to find out if sWlan is alphabet and if so add it to the sData string

but i keep getting compile error
unit1.pas(60,13) Error: Operator is not overloaded


Code: [Select]
Repeat
   begin
    Inc(x);
   sWLAN := COPY(memo1.Text,x,1);

   if sWLAN in ['a'..'z']  then
   begin
   sData :=  sData + sWLAN;
   memo2.text := sData;
   end;
    end;
  Until x = Length(memo1.text); 

« Last Edit: June 25, 2013, 08:44:51 pm by wjackson153 »
Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Error: Operator is not overloaded
« Reply #1 on: June 25, 2013, 08:02:42 pm »
And sWLAN is string? IMO it must be char.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Re: Error: Operator is not overloaded
« Reply #2 on: June 25, 2013, 08:04:54 pm »
yes

sWLAN := Char;

and it's still giving unit1.pas(60,13) Error: Operator is not overloaded
Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Re: Error: Operator is not overloaded
« Reply #3 on: June 25, 2013, 08:07:57 pm »
Here is the complete offending code section

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
   x: Integer;
   sWLAN: Char;
   sData: String;

begin


   Repeat
   begin
    Inc(x);
   sWLAN := COPY(memo1.Text,x,1);

   if sWLAN in ['a'..'z']  then
   begin
   sData :=  sData + sWLAN;
   memo2.text := sData;
   end;
    end;
  Until x = Length(memo1.text);



end;     
Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Error: Operator is not overloaded
« Reply #4 on: June 25, 2013, 08:34:52 pm »
This might be it (cannot assign string to char), and you have 2 options of which i recommend #1:

1)
Code: [Select]
sWLAN := memo1.Text[x];
2)
Code: [Select]
sWLAN := COPY(memo1.Text,x,1)[1];
Neither of these will work if (memo1.Text = ''), so you might need to test that beforehand, unless it'll never be empty.

edit: Second error, you are not initializing x, so:
Code: [Select]
begin
   x:=0;
   //sData:=''; // You might put this for consistency, not sure if required.
   Repeat
      ...
« Last Edit: June 25, 2013, 08:42:15 pm by User137 »

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Re: Error: Operator is not overloaded - (SOLVED)
« Reply #5 on: June 25, 2013, 08:44:26 pm »
Thanks User137 your second method worked a treat , just what I needed :)

Working code below;

Quote
var
sWLAN: Char;
 x: Integer;
 sData: String;

procedure TForm1.Button1Click(Sender: TObject);

begin
     
   Repeat
   begin
    Inc(x);
   sWLAN := COPY(memo1.Text,x,1)[1];

   if sWLAN in ['a'..'z','A'..'Z','0'..'9']  then
     begin
   sData :=  sData + sWLAN;
   memo2.text := sData;
     end;
   end;
  Until x = Length(memo1.text);

end;       
Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

 

TinyPortal © 2005-2018