Recent

Author Topic: TStringBuilder not found but TAnsiStringBuilder found?  (Read 491 times)

fafafooey

  • New Member
  • *
  • Posts: 14
TStringBuilder not found but TAnsiStringBuilder found?
« on: June 28, 2023, 08:43:29 pm »
Hey all, I was messing around with adding verbose logging to my app which would save the lines to a file if an error occurred. I was deciding between TStringList and TStringBuilder but something weird is going on with TStringBuilder. I can only see TAnsiStringBuilder in the identifier completion window but not TStringBuilder. I'm using Lazarus x86 2.2.4, FPC 3.2.2 on Windows 7. This is a windows program in Delphi mode and I have SysUtils in the uses. I think it should be in there since "TStringBuilder = TAnsiStringBuilder" is declared and included in SysUtils. I can't even do "SysUtils.TStringBuilder". What am I not seeing that is preventing TStringBuilder from being declared as a variable?

Thanks for your help in advance!

TRon

  • Hero Member
  • *****
  • Posts: 2506
Re: TStringBuilder not found but TAnsiStringBuilder found?
« Reply #1 on: June 28, 2023, 09:55:05 pm »
First thing that comes to mind is that Lazarus is unable to find the Free Pascal RTL source-files. Have you configured that correctly ? fwiw that is only a problem with code-tools if you insist by typing the name manually then it should compile.

fafafooey

  • New Member
  • *
  • Posts: 14
Re: TStringBuilder not found but TAnsiStringBuilder found?
« Reply #2 on: June 28, 2023, 10:37:29 pm »
Thanks for the reply TRon. My "FPC source directory" in IDE Options -> Environment -> Files is set to the correct FPC source directory. I did this below:

procedure TForm1.FormCreate(Sender: TObject);
var
  x: TStringBuilder;
  y: TAnsiStringBuilder;

begin

  x := TStringBuilder.Create;

  x.Append('Hello');

  y := TAnsiStringBuilder.Create;

  y.Append('Hello');

end;

It compiles fine but the code completion window only shows the following 2 entries:

TAnsiStringBuilder = class
TUnicodeStringBuilder = TAnsiStringBuilder

I'm expecting TStringBuilder to show, right? Does anyone else's Laz 2.2.4 x86 show TStringBuilder or is it like mine?

Thanks!

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TStringBuilder not found but TAnsiStringBuilder found?
« Reply #3 on: June 28, 2023, 10:45:50 pm »
When I Ctrl+click on "TAnsiStringBuilder" in your code, the IDE opens the file "sysstrh.inc" (in the fpc source folders) and it shows:

Code: Pascal  [Select][+][-]
  1. {$define TStringBuilder:=TAnsiStringBuilder}

This means that there is no separate class TStringBuilder, this identifier is just an alias for "TAnsiStringBuilder".

fafafooey

  • New Member
  • *
  • Posts: 14
Re: TStringBuilder not found but TAnsiStringBuilder found?
« Reply #4 on: June 28, 2023, 11:15:28 pm »
Thanks for the reply wp. Yea I saw that too in "sysstrh.inc" but there is also "{$undef TStringBuilder}" before "Type  TStringBuilder = TAnsiStringBuilder;". So I thought there would be a TStringBuilder type in the code completion window. I'm not an expert on compiler defines at all though so if this is the expected behavior then no problem.

I added "TStringBuilder = TAnsiStringBuilder;" under the TForm1 class and the code completion window shows it and the x: TStringBuilder var shows all the TAnsiStringBuilder functions as expected. I just thought TStringBuilder was already a declared type because of that last line in "sysstrh.inc".

Thanks

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: TStringBuilder not found but TAnsiStringBuilder found?
« Reply #5 on: June 28, 2023, 11:20:56 pm »
Code: Pascal  [Select][+][-]
  1. {$define TStringBuilder:=TAnsiStringBuilder}

This means that there is no separate class TStringBuilder, this identifier is just an alias for "TAnsiStringBuilder".

To be more precise: the define is used for the include file which includes a generic implementation for both TAnsiStringBuilder and TUnicodeStringBuilder where TStringBuilder is used as a placeholder (macros don't work across units). So no, there does not exist a TStringBuilder class.

fafafooey

  • New Member
  • *
  • Posts: 14
Re: TStringBuilder not found but TAnsiStringBuilder found?
« Reply #6 on: June 28, 2023, 11:32:50 pm »
Thanks for the reply PascalDragon. I was looking in the FPC source on gitlab and I see these commits for sysstrh.inc, syssbh.inc and syssb.inc:

{$define TGenericStringBuilder:=TAnsiStringBuilder}

TGenericStringBuilder = class

* rename generic TStringBuilder to TGenericStringBuilder to make code tools happy

Does this mean TStringBuilder will show as a type in the code completion window in the current version of FPC?

Thanks!

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: TStringBuilder not found but TAnsiStringBuilder found?
« Reply #7 on: June 28, 2023, 11:37:33 pm »
Does this mean TStringBuilder will show as a type in the code completion window in the current version of FPC?

The important part is the type alias in line 339 of sysstrh.inc. It's simply that Lazarus CodeTools had/has problems if there is a temporary define with the same name in the same unit which is why that was changed. So yes, with the current version of FPC there shouldn't be a problem anymore.

fafafooey

  • New Member
  • *
  • Posts: 14
Re: TStringBuilder not found but TAnsiStringBuilder found?
« Reply #8 on: June 29, 2023, 12:04:03 am »
Ok thanks PascalDragon, my eyes were hurting trying to figure out why I wasn't seeing TStringBuilder. The next version of FPC is looking great btw, great job on it!

 

TinyPortal © 2005-2018