Code convertion error

oxygene
(xiaoguang) #1

Hello,

I try the convertion function to convert the following codes to Oxygene:

string file_Path = $"{Environment.CurrentDirectory}\Log.txt";
using (StreamReader sr = new StreamReader(file_Path))
{
string line;
while ((line = sr.ReadLine()) != null)
{

            }
          
        }

After convert:

var file_Path: String := String.Format(’{0}\Log.txt{1}’, Environment.CurrentDirectory);
using sr := new StreamReader(file_Path) do begin
var line: String;
while assigned(line = sr.ReadLine()) do begin
end;
end;

The problem:

  1. I don’t think {1} is necessary, and I think it should convert to:
    var file_Path:String:=$"{Environment.CurrentDirectory}\Log.txt"; //Which looks the same as the source, just synax different

  2. The line:
    while assigned(line = sr.ReadLine()) do begin //does not work, it will generate error

I have to change to:

while (sr.ReadLine() ≠ nil) do begin
var line: String;
line:=sr.ReadLine;

Regards,
Xiaoguang

0 Likes