Forum > Portuguese

Access the next occurrence of an argument in a TStringList

<< < (3/4) > >>

nightrider43:

--- Code: ---I'll test it and use it if it really works. I just don't understand how the second call uses the IndexOf method with a different signature than the one in the documentation (see marking in the code snippet below).

Thank you very much for the answer and I apologize for not understanding.

uses Classes;

var
  L: TStringList;
  Index: SizeInt;
begin
  L := TStringList.Create;
  try
    L.CommaText := '1,2,3,2,4,5';
    Index := L.IndexOf('2');
    Writeln('First result: ', Index);
    if Index >= 0 then
      Index := TStrings(L).IndexOf('2', Index + 1); <-- This signature differs of that is explained in the documentation.
    Writeln('Second result: ', Index);
  finally
    L.Free;
  end;
  Readln;
end.
--- End code ---
[/quote]

cdbc:
Hi
There are 2 of them:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    // from TStrings...    function IndexOf(const S: string): Integer; overload;    function IndexOf(const S: string; aStart : Integer): Integer; overload;Which one you call depends on the parameters passed in.
Regards Benny

ASerge:

--- Quote from: Remy Lebeau on June 07, 2024, 06:30:26 pm ---If that is not the case in FreePascal, then I would consider that to be a compiler bug.

--- End quote ---
I agree, but are where we are.
A simple example that is not compiled in FPC:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$MODE OBJFPC}{$LONGSTRINGS ON} type  TBase = class  public    procedure Method(V: SizeInt); virtual; // with overload; compiled    procedure Method(const V: string); virtual;  end;   TDerived = class(TBase)    procedure Method(V: SizeInt); override;  end; procedure TDerived.Method(V: SizeInt);begin  inherited;end; procedure TBase.Method(V: SizeInt);beginend; procedure TBase.Method(const V: string);beginend; var  C: TDerived; // with TBase - compiledbegin  C := TDerived.Create;  try    C.Method('12'); // project1.lpr(33,18) Error: Incompatible type for arg no. 1: Got "Constant String", expected "Int64"  finally    C.Free;  end;end.
This example also does not compile in Delphi, because the overload directive is mandatory.

cdbc:
Hi
@ASerge: Those are exactly the 'Shenanigans' I ran into...
Regards Benny

Remy Lebeau:

--- Quote from: ASerge on June 08, 2024, 04:00:29 am ---A simple example that is not compiled in FPC:

--- End quote ---

Which seems to contradict FreePascal's documentation in this case:

https://www.freepascal.org/docs-html/ref/refsu86.html


--- Quote ---The overload modifier tells the compiler that this function is overloaded. It is mainly for Delphi compatibility, as in Free Pascal, all functions and procedures can be overloaded without this modifier.
--- End quote ---

But, the examples given in that page are for free-standing functions, not class methods.  Maybe that makes a difference?


--- Quote from: ASerge on June 08, 2024, 04:00:29 am ---This example also does not compile in Delphi, because the overload directive is mandatory.

--- End quote ---

In Delphi's case, yes.  FreePascal is supposedly more lenient on this.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version