Recent

Author Topic: Simply write in a Text File, Execute a Programm, get Result by reading from Text  (Read 830 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Hello Guys so i Have this Error "File not open" but i cant figure out why the File isn't open.

Can Some1 help ?

Code: Pascal  [Select][+][-]
  1.  
  2. Procedure TBereSD.Black_LBF(prechtl: Boolean);
  3. Var
  4.    ITSDCalcFile : TextFile;
  5.    Bb : TProcess;
  6. Begin
  7.    Bb := TProcess.Create(Nil);
  8.  
  9.    try
  10.       AssignFile(ITSDCalcFile, 'C:\WGKBlck\LBF\ITSDIN.TXT');
  11.       {$I-} // without this, if rewrite fails then a runtime error will be generated
  12.       Rewrite(ITSDCalcFile);
  13.       {$I+}
  14.       if IOResult =0 then begin // OK, we can write the file
  15.          WriteLn('Sample String');   // Getting the Error here: File not Open
  16.          //.. Some other operations with more WriteLN's
  17.  
  18.         Bb.Executable:=('C:\WGKBlck\Lbf\ITSDCalc43.EXE');
  19.         Bb.Parameters.Add('ITSDIN.TXT');
  20.         Bb.Parameters.Add('ITSDOUT.TXT');
  21.  
  22.         Bb.Execute;
  23.         //Ergebniss auswerten
  24.       end else begin
  25.          WriteLn('error opening file for writing');
  26.       end;
  27.    finally
  28.       CloseFile(ITSDCalcFile);
  29.       Bb.Free;
  30.    end;
  31.  
  32.    Zeile := ReadFileToString('C:\WGKBlck\LBF\ITSDOUT.TXT');
  33.    ShowMessage(Zeile)
  34.  
  35.  
  36.   //.. Work With "Zeile"
  37. End;
  38.  
  39.  

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11458
  • FPC developer.
You close when open failed?

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Sh*t did't thought about this Sorry :D

 Corretcted it But still don't lnow why i get The Error .. i Pretty Sure everything is ok. is There something wrong with the path ?
or The do i use any Procedure the Wrong way ?

Edit: Worked with WriteLN(ITSDCalcFile, 'Data')
« Last Edit: January 29, 2021, 11:23:46 am by Weitentaaal »

ASerge

  • Hero Member
  • *****
  • Posts: 2249
And don't forget that the try finally block should start after opening the file (after Rewrite), not before that, so as not to make closing an unopened file.

 

TinyPortal © 2005-2018