Problems readig archive files lazarus / 61-Beginners ---------------------------------------------------------------------- jcaser1948 · 2018-01-22 18:49 I try to rewrite my old Turbopascal MotorCalculation Program in Lazarus. I have still Problems readig existig files Here the code procedure TForm1.MenuItem1Click(Sender: TObject); var    filename: string; begin   if OpenDialog1.Execute then   begin     filename := OpenDialog1.Filename;     ShowMessage(filename);     ReadFile( filename); ;      end; end;  And here is the Procedure Readfile  {-------------------------------------------------------------------- -------} PROCEDURE TForm1.ReadFile( var filevar: string); VAR   LocalMotorname:String;     ok:Boolean;     Answer :Char; BEGIN   REPEAT      LocalMotorname:='????????.MOT';       {DirList; }     WRITELN;      WRITELN('NAME OF FILE TO BE LOADED ?(without extension) ');     READLN(LocalMotorname);    LocalMotorname:= StringUpper(LocalMotorname);      WritelN(LocalMotorname);     LocalMotorname := LocalMotorname + '.MOT';     ok:=false;    StringUpper(LocalMotorname);     writeln;     WRITELN((LocalMotorname),' FILE WILL BE LOADED');      IF NOT FileExists(LocalMotorname)      THEN     BEGIN         WRITELN('CAN NOT find file :',LocalMotorname);                                        WRITELN;                                        WRITELN;                                        ok:=False;                                          END;        IF FileExists(LocalMotorname) THEN          BEGIN        AssignFile(filevar,LocalMotorname);      And here I get this error         datenfile1.pas(1975,26) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "TypedFile"        What can I do to correct the error ?              TRY                  RESET(filevar);  // Open the file for reading                  and here the other error                 datenfile1.pas(1978,31) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "Text"                                                                   // Keep reading lines until the end of the file is reached                 while not eof(filevar) do                 BEGIN                     READLN(filevar,dia);                     READLN(filevar,mes);                     READLN(filevar,anho);                     READLN(filevar,motortyp);                     READLN(filevar,Bearbeiter);                     READLN(filevar,Statorblechnr);                     READLN(filevar,Rotorblechnr);                     READLN(filevar,Angebotsnummer);                     READLN(filevar,kenrot);                     READLN(filevar,schltg);                     READLN(filevar,polzahl);                     READLN(filevar,motfil);                     READLN(filevar,pabkw);                     READLN(filevar,uv);                     READLN(filevar,freq);                     READLN(filevar,cosphi);                     READLN(filevar,etam);                     READLN(filevar,delta);                     READLN(filevar,N1);                     READLN(filevar,n2);                    {some 20 Variable more in the same line}                     READLN(filevar,Brst25);                     READLN(filevar,Rst25);                  {ReadData End}                  ok:=true;                   END;                   except  on E: EInOutError do            writeln('File handling error occurred. Details: ', E.Message);                  end;            CloseFile(filevar);   writeln('File ', LocalMotorname, ' was read. Press enter to continue.');   readln;   Motorname:=LocalMotorname;     WriteDataToScreen;  END;      WRITELN(LocalMotorname,' loaded. Do you want to load another Motor File instead?(Y/N) ');       readln;       If Answer= 'Y' Then ok:= False Else ok:= True;   UNTIL ok=True; END; datenfile1.pas(1975,26) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "TypedFile" Where arises the Type mismatch? Has someone a better example how to read old archives in Lazarus with new components, but using the existing files?(They are Motor Calculation files and it would be very tiresome to write them again) Help would be appreciate ---------------------------------------------------------------------- marcov · 2018-01-22 19:44 That is not a program that would compile in Turbo Pascal either. Assign and reset do take a first argument of type TEXT or TEXTFILE, not filevar: STRING ---------------------------------------------------------------------- lucamar · 2018-01-22 19:50 The type-mismatch arises because filevar *is* a string (as declared in the procedure header) but you're trying to use it as if it were of type file --- p.e. when your code says: AssignFile(filevar,LocalMotorname); What I would do is use LocalMotorname as the parameter of the procedure, declare filevar: Texfile and delete all the start code until:     WRITELN((LocalMotorname),' FILE WILL BE LOADED'); ... After all you have *already* selected a file through the OpenFileDialog!!! ---------------------------------------------------------------------- howardpc · 2018-01-22 20:31 You are trying to mix console-oriented readln code with GUI code in the most inappropriate way. Once you have the name of the file from your OpenDialog1 component, create a TStringList (uses Classes;) and use the LoadFromFile(OpenDialog1.Filename) method of the stringlist to read the file content into the list. You want some variation on this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  sl: TStringList;begin  sl:=TStringList.Create;  try    sl.LoadFromFile(OpenDialog1.Filename);    Assert(sl.Count=,'Unexpected number of lines in '+OpenDialog1.Filename);    dia:=sl[0];    mes:=sl[1];    anho:=sl[2];...    Brst25:=sl[sl.Count-2];    Rst25:=sl[sl.Count-1];... Do something with all the strings you have read...   finally     sl.Free;   end;end; ---------------------------------------------------------------------- jcaser1948 · 2018-01-23 08:50 Dear Howard Pc I Am trying yor solution Here the code so far  {----------------------------------------------- ----------------------------} PROCEDURE TForm1.ReadFile; VAR   filename:string;   LocalMotorname:Textfile;    sl: TStringList;    BEGIN     OpenDialog1.Execute ;    filename:= OpenDialog1.filename;     ShowMessage(Filename);    sl:=TStringList.Create;            try     sl.LoadFromFile(OpenDialog1.Filename);     Assert(sl.Count=81,'Unexpected number of lines in '+OpenDialog1.Filename);     dia:=sl[0];     mes:=sl[1];     anho:=sl[2];     motortyp:= sl[3];     Bearbeiter:= sl[4];     Statorblechnr:= sl[5];     Rotorblechnr:=sl[6];     Angebotsnummer:= sl[7];     kenrot :=StrToFloat(sl[8]);     schltg := sl[9];     polzahl              ..... Kenrot ,schltg....are real numbers , since this is a motorcalculationsprogramm. When  I try to convert Kenrot  from a String to a real number Iget datenfile1.pas(1949,14) Error: Incompatible types: got "Extended" expected "LongInt" Any suggestions? ---------------------------------------------------------------------- Handoko · 2018-01-23 09:15 ~~~ sorry off topic ~~~ Hello sir. When posting in this forum you can make your code more readable by using code tag. First you select the text then click the code tag and choose Pascal. See the image below: ---------------------------------------------------------------------- howardpc · 2018-01-23 09:28 Code snippets are useless. Show the entire code. Is kenrot declared as an Integer rather than Single or Double? In what format are the numbers stored in the text file you are reading? ---------------------------------------------------------------------- jcaser1948 · 2018-01-23 12:27 Quote from: jcaser1948 on January 23, 2018, 09:50:07 amDear Howard Pc I Am trying yor solution Here the code so far  {----------------------------------------------- ----------------------------} Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i PROCEDURE TForm1.ReadFile; VAR  filename:string;  LocalMotorname:Textfile;   sl: TStringList;   BEGIN    OpenDialog1.Execute ;    filename:= OpenDialog1.filename;    ShowMessage(Filename);   sl:=TStringList.Create;           try    sl.LoadFromFile(OpenDialog1.Filename);    Assert(sl.Count=81,'Unexpected number of lines in '+OpenDialog1.Filename);    dia:=sl[0];    mes:=sl[1];    anho:=sl[2];    motortyp:= sl[3];    Bearbeiter:= sl[4];    Statorblechnr:= sl[5];    Rotorblechnr:=sl[6];    Angebotsnummer:= sl[7];    kenrot :=StrToFloat(sl[8]);    schltg := sl[9];    polzahl            .....Kenrot ,schltg....are real numbers , since this is a motorcalculationsprogramm.When  I try to convert Kenrot  from a String to a real number Iget datenfile1.pas(1949,14) Error: Incompatible types: got "Extended" expected "LongInt"Any suggestions?[/quote]Sorry,Knerot,Schltg... were defined as  integersNow it works kenrot :=StrToInt(sl[8]);    schltg :=StrToInt (sl[9]);     polzahl :=StrToInt (sl[10]);       Could you give me a suggestion as how the Writefile would look like? Thanks ---------------------------------------------------------------------- Handoko · 2018-01-23 18:13 I wrote a simplified demo trying to do what you want: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Dialogs, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    btnAdd: TButton;    btnNext: TButton;    btnSave: TButton;    btnRead: TButton;    btnCancel: TButton;    btnPrevious: TButton;    ledDia: TLabeledEdit;    lblHeader: TLabel;    ledMes: TLabeledEdit;    ledAnho: TLabeledEdit;    Notebook1: TNotebook;    Page1: TPage; // Main Menu    Page2: TPage; // Add Data    Page3: TPage; // Read Data    procedure btnCancelClick(Sender: TObject);    procedure btnAddClick(Sender: TObject);    procedure btnNextClick(Sender: TObject);    procedure btnPreviousClick(Sender: TObject);    procedure btnReadClick(Sender: TObject);    procedure btnSaveClick(Sender: TObject);    procedure FormCreate(Sender: TObject);  private    DataIndex: Integer;  end; const  FileName = 'Data.txt'; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  btnCancel.Visible := False;  DataIndex         := 0;end; procedure TForm1.btnCancelClick(Sender: TObject);begin  lblHeader.Caption   := 'I want to:';  Notebook1.PageIndex := 0; // Goto Page 1  btnCancel.Visible   := False;end; procedure TForm1.btnAddClick(Sender: TObject);begin  lblHeader.Caption   := 'Add New Data';  Notebook1.PageIndex := 1; // Goto Page 2  btnCancel.Visible   := True;  ledDia.Text         := '';  ledMes.Text         := '';  ledAnho.Text        := '';  ledDia.Parent       := Page2;  ledMes.Parent       := Page2;  ledAnho.Parent      := Page2;end; procedure TForm1.btnNextClick(Sender: TObject);begin  Inc(DataIndex);  btnReadClick(Self);end; procedure TForm1.btnPreviousClick(Sender: TObject);begin  if (DataIndex > 1) then Dec(DataIndex);  btnReadClick(Self);end; procedure TForm1.btnReadClick(Sender: TObject);var  DataFile   : TextFile;  Index      : Integer;  S1, S2, S3 : string;begin   // Preparation  lblHeader.Caption   := 'Read Data';  Notebook1.PageIndex := 2; // Goto Page 3  btnCancel.Visible   := True;  ledDia.Text         := '';  ledMes.Text         := '';  ledAnho.Text        := '';  ledDia.Parent     := Page3;  ledMes.Parent       := Page3;  ledAnho.Parent      := Page3;   // Find & read the data, temporary store them to S1, S2, S3  if (DataIndex < 1) then DataIndex := 1;  AssignFile(DataFile, Application.Location + FileName);  {$I-}  try    Reset(DataFile);    Index := 0;    while not EOF(DataFile) do    begin      Inc(Index);    ReadLn(DataFile, S1);      ReadLn(DataFile, S2);      ReadLn(DataFile, S3);      if (Index = DataIndex) then Break;    end;    CloseFile(DataFile);  except    ShowMessage('Error reading data.');  end;  if (IOResult <> 0) then  begin    lblHeader.Caption := 'Read Data #0';    Exit;  end;  if (DataIndex > Index) then DataIndex := Index;   // Show the result  lblHeader.Caption := 'Read Data #' + DataIndex.ToString;  ledDia.Text       := S1;  ledMes.Text       := S2;  ledAnho.Text      := S3; end; procedure TForm1.btnSaveClick(Sender: TObject);var  DataFile    : TextFile;  isFileExist : Boolean;  S           : string;begin   // Verify data  if (ledDia.Text = '') or (ledMes.Text = '') or (ledAnho.Text = '') then  begin    ShowMessage('All informations are required.');    Exit;  end;   // Save them  S := Application.Location + FileName;  isFileExist := FileExists(S);  AssignFile(DataFile, S);  {$I-}  try  case isFileExist of      True:  Append(DataFile);      False: Rewrite(DataFile);    end;    WriteLn(DataFile, ledDia.Text);    WriteLn(DataFile, ledMes.Text);    WriteLn(DataFile, ledAnho.Text);  CloseFile(DataFile);  except  end;  if (IOResult <> 0) then ShowMessage('Error saving data.');   // Back to main menu  btnCancelClick(Self); end; end. - It uses TNotebook to avoid multi-forms style GUI - It uses TextFile, the result is human-readable file - Users can add new and view data - Editing and Deleting data haven't implemented - It runs correctly on Linux, I haven't tested it on Windows ---------------------------------------------------------------------- jcaser1948 · 2018-01-23 19:17 Thank you very much Handoko. I will try yor procedure, but right now I have invested a lot of work rewriting the code in the line suggested by howardpc. It seems to work, but wit some doubts. If I shold be unable to get it to work properly, I will take your suggestion Bey the way, as you can see below, I have formatted the Pascalcode according to your frindly suggestion. Thanks again Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i PROCEDURE TForm1.ReadFile; VAR  filename:string;  sl: TStringList;   BEGIN   sl:=TStringList.Create;    OpenDialog1.Execute ;    filename:= OpenDialog1.filename;    ShowMessage(Filename);            try    sl.LoadFromFile(OpenDialog1.Filename);    Assert(sl.Count=81,'Unexpected number of lines in '+OpenDialog1.Filename);    dia:=sl[0];    mes:=sl[1];    anho:=sl[2];    motortyp:= sl[3];    Bearbeiter:= sl[4];    Statorblechnr:= sl[5];    Rotorblechnr:=sl[6];    Angebotsnummer:= sl[7];    kenrot :=StrToInt(sl[8]);    schltg :=StrToInt (sl[9]);    polzahl :=StrToInt (sl[10]);    motfil  :=StrToInt (sl[11]);    pabkw := StrToFloat (sl[12]);    uv      := StrToFloat (sl[13]);       ...     Rst25:= StrToFloat (sl[80]);             finally   sl.Free;               end;    WriteDataToScreen;END;       SL has also 80 lines This compiles without error. I need to make also the "writefe" ,procedure, als its Counterpart So I wrote Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i PROCEDURE TForm1.WriteFile;VAR {filename:string; ,it seems not to be necessary}    sl: TStringList;   BEGIN   sl:=TStringList.Create;    if SaveDialog1.Execute then      Begin     sl.SaveToFile( SaveDialog1.Filename );      try    sl[0]:=dia;    sl[1]:=mes;    sl[2]:=anho;    sl[3]:=motortyp;    sl[4]:=Bearbeiter;    sl[5]:=Statorblechnr;    sl[6]:=Rotorblechnr;    sl[7]:=Angebotsnummer;    sl[8]:=IntToStr( kenrot);    sl[9]:=IntToStr (schltg);    sl[10]:=IntToStr (polzahl);    sl[11]:=IntToStr (motfil);    sl[12]:= FloatToStr (pabkw);    sl[13]:= FloatToStr( uv );     .......      sl[77]:= FloatToStr(Rst28);    sl[78] := FloatToStr (Rst29);    sl[79]:= FloatToStr (Brst25);     sl[80]:= FloatToStr (Rst25);    Assert(sl.Count=81,'Unexpected number of lines in '+SaveDialog1.Filename);      finally   sl.Free;                 end;    End;     Showmessage('Motor data saved on File');       This code compiles, but gives runtime error.     I guess it is because I have not given the length of Sl.How can I do that?.Is that necessary?How can I improve the code without so much fuss? Thanks again for the help ---------------------------------------------------------------------- howardpc · 2018-01-23 22:03 Try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.WriteFile;var  sl: TStringList;begin  if SaveDialog1.Execute then  begin    sl:=TStringList.Create;    try      sl.Add(dia);      sl.Add(mes);      sl.Add(anho);      sl.Add(motortyp);      sl.Add(Bearbeiter);      sl.Add(Statorblechnr);      sl.Add(Rotorblechnr);      sl.Add(Angebotsnummer);      sl.Add(IntToStr(kenrot));      sl.Add(IntToStr(schltg));      sl.Add(IntToStr(polzahl));      sl.Add(IntToStr(motfil));      sl.Add(FloatToStr(pabkw));      sl.Add(FloatToStr( uv ));      ...    sl.Add(FloatToStr(Rst28));      sl.Add(FloatToStr(Rst29));      sl.Add(FloatToStr(Brst25));      sl.Add(FloatToStr(Rst25));      Assert(sl.Count=81,'programmer''s error');      sl.SaveToFile(SaveDialog1.FileName);      Showmessage('Motor data saved on File');    finally      sl.Free;  end;end; ---------------------------------------------------------------------- jcaser1948 · 2018-01-24 08:42 Quote from: howardpc on January 23, 2018, 11:03:41 pmTry this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.WriteFile;var  sl: TStringList;begin  if SaveDialog1.Execute then  begin    sl:=TStringList.Create;    try      sl.Add(dia);      sl.Add(mes);      sl.Add(anho);      sl.Add(motortyp);      sl.Add(Bearbeiter);      sl.Add(Statorblechnr);      sl.Add(Rotorblechnr);      sl.Add(Angebotsnummer);      sl.Add(IntToStr(kenrot));      sl.Add(IntToStr(schltg));      sl.Add(IntToStr(polzahl));      sl.Add(IntToStr(motfil));      sl.Add(FloatToStr(pabkw));      sl.Add(FloatToStr( uv ));      ...    sl.Add(FloatToStr(Rst28));      sl.Add(FloatToStr(Rst29));      sl.Add(FloatToStr(Brst25));      sl.Add(FloatToStr(Rst25));      Assert(sl.Count=81,'programmer''s error');      sl.SaveToFile(SaveDialog1.FileName);      Showmessage('Motor data saved on File');    finally      sl.Free;  end;end; Dear HowardPc I have  reduced your procedure in oder to test it  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i PROCEDURE TForm1.WriteFile;VAR    sl: TStringList;   BEGIN     if SaveDialog1.Execute then          sl:=TStringList.Create;      Begin   sl.SaveToFile( SaveDialog1.Filename );      try       sl.Add(dia);    sl.Add(mes);      sl.Add(anho);      sl.Add(motortyp);      sl.Add(Bearbeiter);      sl.Add(Statorblechnr);      sl.Add(Rotorblechnr);      sl.Add(Angebotsnummer);      sl.Add(IntToStr(kenrot));      sl.Add(IntToStr(schltg));      sl.Add(IntToStr(polzahl));      sl.Add(IntToStr(motfil));      sl.Add(FloatToStr(pabkw));      sl.Add(FloatToStr( uv ));        finally      sl.Free;     End; END;  ROCEDURE TForm1.ReadFile; {This is the next procedure, where the Compiler stops I have changed the position of "Writefile" in the code, to ensure it was really a problem of Writefile and not of the next procedure.It seems it is a problem of writefile itself, but I am unable to find the error}}      When I try to compile it , I get the error datenfile1.pas(1961,1) Error: Illegal expression datenfile1.pas(1961,11) Fatal: Syntax error, ";" expected but "identifier TFORM1" found ---------------------------------------------------------------------- howardpc · 2018-01-24 08:52 What are the contents of datenfile1.pas? It looks as though you omitted a needed semicolon, perhaps the end of line 1960. Without seeing the offending code it is impossible to say for certain. ---------------------------------------------------------------------- Handoko · 2018-01-24 09:26 Let's analyze the structure of the code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.WriteFile;var  sl: TStringList;begin  if SaveDialog1.Execute then  begin    sl:=TStringList.Create;    try      sl.Add ...      ...      Showmessage('Motor data saved on File');    finally      sl.Free;  end;end; The procedure WriteFile has: - 2 begins (line #4 and line #6) - 2 ends (line #14 and line #15) - But you forgot an end for the try block (line #8) ---------------------------------------------------------------------- jcaser1948 · 2018-01-24 10:05 Quote from: Handoko on January 24, 2018, 10:26:38 amLet's analyze the structure of the code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.WriteFile;var  sl: TStringList;begin  if SaveDialog1.Execute then  begin    sl:=TStringList.Create;    try      sl.Add ...      ...      Showmessage('Motor data saved on File');    finally      sl.Free;  end;end; The procedure WriteFile has: - 2 begins (line #4 and line #6) - 2 ends (line #14 and line #15) - But you forgot an end for the try block (line #8) Thanks Hadoko. What a silly error. Now it compiles ---------------------------------------------------------------------- jcaser1948 · 2018-01-24 15:09 I have another question. Now I car read an write the Motorfiles, but i f I create a motorfile and, in the process of creating it, I cancel the filecreation(It means I do not give any File name) I get a run time error. This is a logical development since I lack a sort of "Default name" or something similar. How could I improve the code     Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.WriteFile;    var      sl: TStringList;    begin      if SaveDialog1.Execute then      begin        sl:=TStringList.Create;      try          sl.Add ...          ...          Showmessage('Motor data saved on File');        finally          sl.Free;      end;    end; so that this error do not arise? Thanks again to all ---------------------------------------------------------------------- Bart · 2018-01-24 15:56 If you do not give a filename, OpenDialog1 will not return TRUE, so this error should not occur. Bart ---------------------------------------------------------------------- howardpc · 2018-01-24 16:26 In other words the runtime error you get does not arise from the code snippet you showed. To get meaningful help from the forum: if you are asking about an error state exactly what it is. Which runtime error? What is the error message?give the full compilable code that produces the error. Then someone else can reproduce it and debug it on their computer instead of having to resort to crystal ball methods to guess at what you have not shown or stated about your set- up.often details of your OS/platform may also be relevant - sometimes 32-bit code is not equivalent to 64-bit code etc. ---------------------------------------------------------------------- Handoko · 2018-01-24 16:42 @jcaser1948 Lots of things can be done to improve the code. Here are some general advices: - Bad input equals bad output (aka garbage in, garbage out) Don't trust any data you received. Write some codes to check any input before you use it, save it or continue to the next process. Always check if it is empty or not, and it is in the acceptable range. If it is not valid, show a message to the user and abort the following process, you can use Exit command for this. - Write the code neatly Format the code to make it readable by using proper blank lines, spaces, indentations. Give proper names for variables, constants, etc. Provide some comments when needed. You can find and fix bugs much easier if the code is nicely written. - Use Divide and Conquer strategy When you find hard to solve problem in programming, try to divide it into several sub processes. Start new project for each of the sub process for testing. Only you're sure they works correctly, then merge it back to the main project. Don't do testings on the 'real' project, it can introduce many new bugs. - Have enough sleep Concentration is very important for a programmer. I write buggy codes when I am sleepy. ---------------------------------------------------------------------- jcaser1948 · 2018-01-24 17:32 Quote from: Bart on January 24, 2018, 04:56:57 pmIf you do not give a filename, OpenDialog1 will not return TRUE, so this error should not occur. Bart Dear bart As Old Galillei woud say"E pui si move", also it happens nevertheless This is the error I get if a do not give a filename and abort the save dialog. It is in Spanish, but esy to understand, since most technical words in English are of Latin origin, and have therefore the same roots El proyecto DatenEingabe ha lanzado una excepción de la clase 'External: SIGSEGV'.  En archivo 'datenfile1.pas' en linea 2035: sl.SaveToFile( SaveDialog1.Filename ); ---------------------------------------------------------------------- Handoko · 2018-01-24 18:13 I noticed something not correct. I compare your code with howardpc's code. You modified it wrong: This is original howardpc's code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.WriteFile;var  sl: TStringList;begin  if SaveDialog1.Execute then  begin    sl:=TStringList.Create;    try      sl.Add(dia);      sl.Add(mes); This is yours: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i PROCEDURE TForm1.WriteFile;VAR    sl: TStringList;   BEGIN     if SaveDialog1.Execute then          sl:=TStringList.Create;      Begin   sl.SaveToFile( SaveDialog1.Filename );      try       sl.Add(dia);    sl.Add(mes); Can you see the different? The problem is on the if-block. -edit- I also found another bug. Can you find it? ---------------------------------------------------------------------- jcaser1948 · 2018-01-26 06:37 Quote from: Handoko on January 24, 2018, 07:13:45 pmI noticed something not correct. I compare your code with howardpc's code. You modified it wrong: This is original howardpc's code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.WriteFile;var  sl: TStringList;begin  if SaveDialog1.Execute then  begin    sl:=TStringList.Create;    try      sl.Add(dia);      sl.Add(mes); This is yours: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i PROCEDURE TForm1.WriteFile;VAR    sl: TStringList;   BEGIN     if SaveDialog1.Execute then          sl:=TStringList.Create;      Begin   sl.SaveToFile( SaveDialog1.Filename );      try       sl.Add(dia);    sl.Add(mes); Can you see the different? The problem is on the if-block. -edit- I also found another bug. Can you find it? Thanks, I see the problem and I have corrected it. Also the other error, consisting sin saving the file at the beginning and at the end again Thanks, you have helped me a lot. This matter is solved