Forum > Portuguese
Access the next occurrence of an argument in a TStringList
cdbc:
Hi
Thanks @ASerge, that was golden insight on your part, I totally overlooked it.
I've just now implemented, surfacing the method in my "IStringList", so if you use that, you don't have to typecast...
If it could be of interest, you can find it(v 5.07.06.2024) here: https://gitlab.com/cdbc-public/ibcstringlist
Regards Benny
ASerge:
--- Quote from: cdbc on June 07, 2024, 07:41:17 am ---If it could be of interest, you can find it(v 5.07.06.2024) here: https://gitlab.com/cdbc-public/ibcstringlist
--- End quote ---
OK, I looked at the source code. There are questions and suggestions.
1. You can use a constant when declaring the interface IID
--- 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";}};} ---IStringList = interface(IInterface)[SGUIDIStringList]
2. It is necessary to repeat the method header in the implementation. Example:
--- 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";}};} ---function QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid : tguid;out obj) : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};...function TiStringList.QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid : tguid;out obj) : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; Otherwise, as in your case, you got an explicit cdecl declaration in the implementation, because you edited on unix, but on Windows there should be stdcall, and the unit is not even compiled.
3. Why are some of the functions in the implementation virtual? Are you going to make several implementations?
4. There is no need for a constructor that just calls the inherited one and does nothing by itself.
5. You have copied the implementation code for the indexOf function. Maybe it was easier this way:
--- 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";}};} ---function TiStringList.IndexOf(const S: string): Integer;begin Result := inherited;end; function TiStringList.IndexOf(const S: string; aStart: Integer): Integer;begin Result := TStrings(Self).IndexOf(S, aStart);end;
5. There is no need for the IslStringsEnumerable type at all. The compiler recognizes GetEnumerator.
cdbc:
Hi
@ASerge: Thanks mate.
1) I simply forgot halfway... what I was doing.
2) I didn't know that and overlooked it, so used to 'cdecl', that I don't see it,
fixed it.
3) I usually make protected methods virtual, just in case, but no, I don't
think I'll make more versions... so I removed them.
4) Removed, you're right, it's enough TStringList does it ;)
5) I kinda forgot how it goes with skipping an override, so I lifted the code.
EDIT: Tried your code and got a fat AV in that exact line 'TStrings(Self)...'
The copied code stays.
6) Dotting the i's and crossing the t's... and didn't know that.
Thank you for the review, I've followed your suggestions and learnt a couple of new things along the way 8)
Regards Benny
Remy Lebeau:
--- Quote from: ASerge on June 07, 2024, 03:59:07 am ---
--- Quote from: Remy Lebeau on June 07, 2024, 03:17:54 am ---You shouldn't need the type-cast since...
--- End quote ---
Should. TStringList overrides only one indexOf.
--- End quote ---
And? Yes, it overrides a virtual method, but that shouldn't change the visibility of other overloads. Both overloads of TStrings.IndexOf() are public, and so both should be callable on a TStringList object variable without casting. If that is not the case in FreePascal, then I would consider that to be a compiler bug.
--- Quote from: ASerge on June 07, 2024, 03:59:07 am ---Try it yourself.
--- End quote ---
I don't have FreePascal installed. But it works fine in Delphi.
bytebites:
If you add overload directive then Index := L.IndexOf('2', Index + 1); works without type cast.
--- 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";}};} ---TStringList = class(TStrings) function IndexOf(const S: string): Integer; override;
Navigation
[0] Message Index
[#] Next page
[*] Previous page