With keyword

Issue #190 resolved
Toky Olivier Razanakotonarivo created an issue

Hello,

How to use the “WITH” keyword please in DWS? If it’s not implemented, what is the alternative?

Sometimes, it’s difficult to work without it.

Thank you.

Comments (3)

  1. Eric Grange repo owner

    with is supported with explicitly named aliases only, below is an exemple taken from the test cases. It is essentially a combination of a “var” and a “begin” sub-block.

    with a := 1 do
        PrintLn(a);
    
    with b := "a", d := 3 do begin
        with c := b + "c" do
            PrintLn(c);
        PrintLn(d);
        with c : Integer = d + 1 do
            PrintLn(c);
    end;
    

  2. Toky Olivier Razanakotonarivo reporter

    Thank you but finally, how to write this then in DWS?

    //Decls
    type 
      MyRec = record
        x, y: Integer;
      end;
    
    var rec: MyRec;
    
    //Usage
    
    with rec do begin
      x := 5;
      y := 20;
    end;
    

    Only like this?

    rec.x := 5;
    rec.y := 20;
    

    So the standard action with the WITH keyword is not supported?

  3. Log in to comment