xsharp.eu • USING syntax ? - help please ... - Page 3
Page 3 of 3

USING syntax ? - help please ...

Posted: Fri May 04, 2018 1:44 pm
by Phil Hepburn
Hi Robert and all,

Thanks for the multiple USING syntax.

I have applied the syntax to part of a sample I am currently doing for ClickStartXSharp, involving Await methods in 'Stream' classes.

The code is below - it reads one file and creates two more with the read contents :-

Code: Select all

public async method MyStreamReaderWriterTest(cFilePath as string, cNuFile1 as string, cNuFile2 as string) as void
        if File.Exists(cFilePath)
            begin using local sw1 := StreamWriter{cNuFile1}, ;  
                              sw2 := StreamWriter{cNuFile2} as StreamWriter 

                begin using local sr := StreamReader{cFilePath} as StreamReader
                    local cDetails as string
                    try
                        local cResult := "" as string
                        cResult := await sr:ReadToEndAsync()
                        MessageBox.Show(cResult,"File contents :")
                        await sw1:WriteAsync(cResult)
                        await sw2:WriteAsync(cResult)
                    catch oEX as SystemException
                        MessageBox.Show(oEX:Message,"my Error buffering :")
                    end try
                end using
            end using
        else
            MessageBox.Show("No such file found on disc ....","my Error file reading :")
        endif
    return
My problem is how to write code so that all three are in one USING statement.

Is this possible ?

Personally, I think I could make it more readable to help keep Wolfgang happy, but is it allowed, and if so what is the syntax ?

Here is the result :-
MultipleUsings_01.png
MultipleUsings_01.png (25.83 KiB) Viewed 163 times
Regards,
Phil.