object and "with" construction

Issue #226 resolved
Alex Bespalov created an issue
program test;
begin
  Print(TObject.Create.Classname);//thats works fine

//  with TObject.Create do   //error “Colon ":" expected” throwed.
//    Print(Classname);   
end.

Comments (3)

  1. Eric Grange repo owner

    Legacy anonymous "with" constructs are not allowed, you have to use the named aliasing syntax

    with obj := TObject.Create do begin
       ...
    end;
    
  2. Alex Bespalov reporter
      with obj := TObject.Create do
        Print(Classname);             //error "Unknown name "Classname""
    

    thats mean no sense to use “with….do” constructions for objects.

    Ok, well understood, thank you.

  3. Alex Bespalov reporter

    @Eric Grange

    I make alternative with … do realization for correct completion of construction like

       with TFileStream.Create(path,mode) do
       try
          tempstr := data + #13#10;
          Seek(0, soFromEnd);
          WriteBuffer(tempstr,(Length(data)+2)*2);
       finally
          Free;
       end;
    

    can be switched in compiler options.

    Do you interested in?

    BTW, Free for Delphi objects doesnt called real object Free or Destroy. Also fixed.

    P.S. To expand previous question - i have TOO MUCH changes, fixes, remaking etc in DWS since Feb 2022 (have no possibility to make some commits, internet was limited). Some of them, i think, will be principally not interesting for you (like implementing of specialized integer & floating types in addition to common integer and float, Linux & MacOs implementation, etc etc), but not all.

    The great problem is to split this changes to commits, so i dont want to spend a lot of time, if you are not interested in.

  4. Log in to comment