[DELPHI] Ошибка в коде!

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by Sokol-117845, 10 Apr 2012.

  1. Sokol-117845

    Sokol-117845 New Member

    Joined:
    7 Jun 2011
    Messages:
    2
    Likes Received:
    1
    Reputations:
    0
    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    var ts:TStringList;
       i : integer;
       s : string;
    begin
      ts := TStringList.Create;
      try
        ts.LoadFromFile('Исходный.txt');
        for i:=0 to ts.Count-1 do begin
          if copy(ts.Strings[i],1,2)='11' then
           begin 
            Delete(ts.Strings[i],1,2);
            with TFileStream.Create('Имяфайла.txt',fmCreate or fmOpenWrite or fmShareDenyWrite) do
             begin
              Seek(Size,soBeginning);
              Write(PChar(ts.Strings[i])[0],Length(ts.Strings[i]));
              Free;
             end;
           end;
         end;
         ts.SaveToFile('1.txt');
      finally
         ts.Free;
    end;
    end;
    
    Code:
    Delete(ts.Strings[i],1,2);
    ^^^ компилятор ругается на эту строчку!
    Constant object cannotbe passed as var parameter
    Где я допустил ошибку?
     
  2. mironich

    mironich Elder - Старейшина

    Joined:
    27 Feb 2011
    Messages:
    733
    Likes Received:
    73
    Reputations:
    19
    Нелзя свойство обьекта var параметром передавать(ссылкой).
    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    var ts:TStringList;
       i : integer;
       s,[B]TmpStr[/B]: string;
    begin
      ts := TStringList.Create;
      try
        ts.LoadFromFile('Исходный.txt');
        for i:=0 to ts.Count-1 do begin
          if copy(ts.Strings[i],1,2)='11' then
           begin 
           [B]TmpStr[/B] := ts.Strings[i];
            Delete([B]TmpStr[/B],1,2);
            with TFileStream.Create('Имяфайла.txt',fmCreate or fmOpenWrite or fmShareDenyWrite) do
             begin
              Seek(Size,soBeginning);
              Write(PChar([B]TmpStr[/B])[0],Length([B]TmpStr[/B]));
              Free;
             end;
           end;
         end;
         ts.SaveToFile('1.txt');
      finally
         ts.Free;
    end;
    end;