Recent

Author Topic: Problems readig archive files  (Read 13302 times)

jcaser1948

  • Jr. Member
  • **
  • Posts: 68
Problems readig archive files
« on: January 22, 2018, 07:49:31 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 11938
  • FPC developer.
Re: Problems readig archive files
« Reply #1 on: January 22, 2018, 08:44:08 pm »
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

  • Hero Member
  • *****
  • Posts: 4219
Re: Problems readig archive files
« Reply #2 on: January 22, 2018, 08:50:46 pm »
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!!!
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Problems readig archive files
« Reply #3 on: January 22, 2018, 09:31:18 pm »
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][+][-]
  1. var
  2.   sl: TStringList;
  3. begin
  4.   sl:=TStringList.Create;
  5.   try
  6.     sl.LoadFromFile(OpenDialog1.Filename);
  7.     Assert(sl.Count=<whatever>,'Unexpected number of lines in '+OpenDialog1.Filename);
  8.     dia:=sl[0];
  9.     mes:=sl[1];
  10.     anho:=sl[2];
  11. ...
  12.     Brst25:=sl[sl.Count-2];
  13.     Rst25:=sl[sl.Count-1];
  14. ...
  15. Do something with all the strings you have read
  16. ...
  17.    finally
  18.      sl.Free;
  19.    end;
  20. end;

jcaser1948

  • Jr. Member
  • **
  • Posts: 68
Re: Problems readig archive files
« Reply #4 on: January 23, 2018, 09:50:07 am »
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

  • Hero Member
  • *****
  • Posts: 5376
  • My goal: build my own game engine using Lazarus
Re: Problems readig archive files
« Reply #5 on: January 23, 2018, 10:15:28 am »
~~~ 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

  • Hero Member
  • *****
  • Posts: 4144
Re: Problems readig archive files
« Reply #6 on: January 23, 2018, 10:28:23 am »
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

  • Jr. Member
  • **
  • Posts: 68
Re: Problems readig archive files
« Reply #7 on: January 23, 2018, 01:27:20 pm »
Dear Howard Pc
I Am trying yor solution
Here the code so far  {---------------------------------------------------------------------------}
Code: Pascal  [Select][+][-]
  1. PROCEDURE TForm1.ReadFile;
  2.  
  3. VAR
  4.   filename:string;
  5.   LocalMotorname:Textfile;
  6.    sl: TStringList;
  7.    BEGIN
  8.     OpenDialog1.Execute ;
  9.  
  10.    filename:= OpenDialog1.filename;
  11.     ShowMessage(Filename);
  12.    sl:=TStringList.Create;
  13.            try
  14.     sl.LoadFromFile(OpenDialog1.Filename);
  15.     Assert(sl.Count=81,'Unexpected number of lines in '+OpenDialog1.Filename);
  16.     dia:=sl[0];
  17.     mes:=sl[1];
  18.     anho:=sl[2];
  19.     motortyp:= sl[3];
  20.     Bearbeiter:= sl[4];
  21.     Statorblechnr:= sl[5];
  22.     Rotorblechnr:=sl[6];
  23.     Angebotsnummer:= sl[7];
  24.     kenrot :=StrToFloat(sl[8]);
  25.     schltg := sl[9];
  26.     polzahl              .....
  27. Kenrot ,schltg....are real numbers , since this is a motorcalculationsprogramm.
  28. When  I try to convert Kenrot  from a String to a real number Iget
  29. datenfile1.pas(1949,14) Error: Incompatible types: got "Extended" expected "LongInt"
  30. Any suggestions?
  31. [/quote]
  32. Sorry,
  33. Knerot,Schltg... were defined as  integers
  34. Now it works
  35.  kenrot :=StrToInt(sl[8]);
  36.     schltg :=StrToInt (sl[9]);
  37.  
  38.     polzahl :=StrToInt (sl[10]);
     


Could you give me a suggestion as how the Writefile would look like?
Thanks

Handoko

  • Hero Member
  • *****
  • Posts: 5376
  • My goal: build my own game engine using Lazarus
Re: Problems readig archive files
« Reply #8 on: January 23, 2018, 07:13:20 pm »
I wrote a simplified demo trying to do what you want:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Dialogs, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     btnAdd: TButton;
  16.     btnNext: TButton;
  17.     btnSave: TButton;
  18.     btnRead: TButton;
  19.     btnCancel: TButton;
  20.     btnPrevious: TButton;
  21.     ledDia: TLabeledEdit;
  22.     lblHeader: TLabel;
  23.     ledMes: TLabeledEdit;
  24.     ledAnho: TLabeledEdit;
  25.     Notebook1: TNotebook;
  26.     Page1: TPage; // Main Menu
  27.     Page2: TPage; // Add Data
  28.     Page3: TPage; // Read Data
  29.     procedure btnCancelClick(Sender: TObject);
  30.     procedure btnAddClick(Sender: TObject);
  31.     procedure btnNextClick(Sender: TObject);
  32.     procedure btnPreviousClick(Sender: TObject);
  33.     procedure btnReadClick(Sender: TObject);
  34.     procedure btnSaveClick(Sender: TObject);
  35.     procedure FormCreate(Sender: TObject);
  36.   private
  37.     DataIndex: Integer;
  38.   end;
  39.  
  40. const
  41.   FileName = 'Data.txt';
  42.  
  43. var
  44.   Form1: TForm1;
  45.  
  46. implementation
  47.  
  48. {$R *.lfm}
  49.  
  50. { TForm1 }
  51.  
  52. procedure TForm1.FormCreate(Sender: TObject);
  53. begin
  54.   btnCancel.Visible := False;
  55.   DataIndex         := 0;
  56. end;
  57.  
  58. procedure TForm1.btnCancelClick(Sender: TObject);
  59. begin
  60.   lblHeader.Caption   := 'I want to:';
  61.   Notebook1.PageIndex := 0; // Goto Page 1
  62.   btnCancel.Visible   := False;
  63. end;
  64.  
  65. procedure TForm1.btnAddClick(Sender: TObject);
  66. begin
  67.   lblHeader.Caption   := 'Add New Data';
  68.   Notebook1.PageIndex := 1; // Goto Page 2
  69.   btnCancel.Visible   := True;
  70.   ledDia.Text         := '';
  71.   ledMes.Text         := '';
  72.   ledAnho.Text        := '';
  73.   ledDia.Parent       := Page2;
  74.   ledMes.Parent       := Page2;
  75.   ledAnho.Parent      := Page2;
  76. end;
  77.  
  78. procedure TForm1.btnNextClick(Sender: TObject);
  79. begin
  80.   Inc(DataIndex);
  81.   btnReadClick(Self);
  82. end;
  83.  
  84. procedure TForm1.btnPreviousClick(Sender: TObject);
  85. begin
  86.   if (DataIndex > 1) then Dec(DataIndex);
  87.   btnReadClick(Self);
  88. end;
  89.  
  90. procedure TForm1.btnReadClick(Sender: TObject);
  91. var
  92.   DataFile   : TextFile;
  93.   Index      : Integer;
  94.   S1, S2, S3 : string;
  95. begin
  96.  
  97.   // Preparation
  98.   lblHeader.Caption   := 'Read Data';
  99.   Notebook1.PageIndex := 2; // Goto Page 3
  100.   btnCancel.Visible   := True;
  101.   ledDia.Text         := '';
  102.   ledMes.Text         := '';
  103.   ledAnho.Text        := '';
  104.   ledDia.Parent       := Page3;
  105.   ledMes.Parent       := Page3;
  106.   ledAnho.Parent      := Page3;
  107.  
  108.   // Find & read the data, temporary store them to S1, S2, S3
  109.   if (DataIndex < 1) then DataIndex := 1;
  110.   AssignFile(DataFile, Application.Location + FileName);
  111.   {$I-}
  112.   try
  113.     Reset(DataFile);
  114.     Index := 0;
  115.     while not EOF(DataFile) do
  116.     begin
  117.       Inc(Index);
  118.       ReadLn(DataFile, S1);
  119.       ReadLn(DataFile, S2);
  120.       ReadLn(DataFile, S3);
  121.       if (Index = DataIndex) then Break;
  122.     end;
  123.     CloseFile(DataFile);
  124.   except
  125.     ShowMessage('Error reading data.');
  126.   end;
  127.   if (IOResult <> 0) then
  128.   begin
  129.     lblHeader.Caption := 'Read Data #0';
  130.     Exit;
  131.   end;
  132.   if (DataIndex > Index) then DataIndex := Index;
  133.  
  134.   // Show the result
  135.   lblHeader.Caption := 'Read Data #' + DataIndex.ToString;
  136.   ledDia.Text       := S1;
  137.   ledMes.Text       := S2;
  138.   ledAnho.Text      := S3;
  139.  
  140. end;
  141.  
  142. procedure TForm1.btnSaveClick(Sender: TObject);
  143. var
  144.   DataFile    : TextFile;
  145.   isFileExist : Boolean;
  146.   S           : string;
  147. begin
  148.  
  149.   // Verify data
  150.   if (ledDia.Text = '') or (ledMes.Text = '') or (ledAnho.Text = '') then
  151.   begin
  152.     ShowMessage('All informations are required.');
  153.     Exit;
  154.   end;
  155.  
  156.   // Save them
  157.   S := Application.Location + FileName;
  158.   isFileExist := FileExists(S);
  159.   AssignFile(DataFile, S);
  160.   {$I-}
  161.   try
  162.     case isFileExist of
  163.       True:  Append(DataFile);
  164.       False: Rewrite(DataFile);
  165.     end;
  166.     WriteLn(DataFile, ledDia.Text);
  167.     WriteLn(DataFile, ledMes.Text);
  168.     WriteLn(DataFile, ledAnho.Text);
  169.     CloseFile(DataFile);
  170.   except
  171.   end;
  172.   if (IOResult <> 0) then ShowMessage('Error saving data.');
  173.  
  174.   // Back to main menu
  175.   btnCancelClick(Self);
  176.  
  177. end;
  178.  
  179. 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

  • Jr. Member
  • **
  • Posts: 68
Re: Problems readig archive files
« Reply #9 on: January 23, 2018, 08:17:04 pm »
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][+][-]
  1. PROCEDURE TForm1.ReadFile;
  2.  VAR
  3.   filename:string;
  4.   sl: TStringList;
  5.    BEGIN
  6.    sl:=TStringList.Create;
  7.     OpenDialog1.Execute ;
  8.     filename:= OpenDialog1.filename;
  9.     ShowMessage(Filename);
  10.  
  11.            try
  12.     sl.LoadFromFile(OpenDialog1.Filename);
  13.     Assert(sl.Count=81,'Unexpected number of lines in '+OpenDialog1.Filename);
  14.     dia:=sl[0];
  15.     mes:=sl[1];
  16.     anho:=sl[2];
  17.     motortyp:= sl[3];
  18.     Bearbeiter:= sl[4];
  19.     Statorblechnr:= sl[5];
  20.     Rotorblechnr:=sl[6];
  21.     Angebotsnummer:= sl[7];
  22.     kenrot :=StrToInt(sl[8]);
  23.     schltg :=StrToInt (sl[9]);
  24.     polzahl :=StrToInt (sl[10]);
  25.     motfil  :=StrToInt (sl[11]);
  26.     pabkw   := StrToFloat (sl[12]);
  27.     uv      := StrToFloat (sl[13]);  
  28.     ...
  29.      Rst25:= StrToFloat (sl[80]);
  30.              finally   sl.Free;
  31.                  end;
  32.     WriteDataToScreen;
  33. 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][+][-]
  1. PROCEDURE TForm1.WriteFile;
  2. VAR {filename:string; ,it seems not to be necessary}
  3.     sl: TStringList;
  4.    BEGIN
  5.    sl:=TStringList.Create;
  6.     if SaveDialog1.Execute then
  7.       Begin
  8.      sl.SaveToFile( SaveDialog1.Filename );
  9.       try
  10.     sl[0]:=dia;
  11.     sl[1]:=mes;
  12.     sl[2]:=anho;
  13.     sl[3]:=motortyp;
  14.     sl[4]:=Bearbeiter;
  15.     sl[5]:=Statorblechnr;
  16.     sl[6]:=Rotorblechnr;
  17.     sl[7]:=Angebotsnummer;
  18.     sl[8]:=IntToStr( kenrot);
  19.     sl[9]:=IntToStr (schltg);
  20.     sl[10]:=IntToStr (polzahl);
  21.     sl[11]:=IntToStr (motfil);
  22.     sl[12]:= FloatToStr (pabkw);
  23.     sl[13]:= FloatToStr( uv );
  24.     .......
  25.       sl[77]:= FloatToStr(Rst28);
  26.     sl[78] := FloatToStr (Rst29);
  27.     sl[79]:= FloatToStr (Brst25);
  28.  
  29.     sl[80]:= FloatToStr (Rst25);
  30.     Assert(sl.Count=81,'Unexpected number of lines in '+SaveDialog1.Filename);
  31.       finally   sl.Free;
  32.                  end;
  33.     End;
  34.  
  35.     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

  • Hero Member
  • *****
  • Posts: 4144
Re: Problems readig archive files
« Reply #10 on: January 23, 2018, 11:03:41 pm »
Try this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.WriteFile;
  2. var
  3.   sl: TStringList;
  4. begin
  5.   if SaveDialog1.Execute then
  6.   begin
  7.     sl:=TStringList.Create;
  8.     try
  9.       sl.Add(dia);
  10.       sl.Add(mes);
  11.       sl.Add(anho);
  12.       sl.Add(motortyp);
  13.       sl.Add(Bearbeiter);
  14.       sl.Add(Statorblechnr);
  15.       sl.Add(Rotorblechnr);
  16.       sl.Add(Angebotsnummer);
  17.       sl.Add(IntToStr(kenrot));
  18.       sl.Add(IntToStr(schltg));
  19.       sl.Add(IntToStr(polzahl));
  20.       sl.Add(IntToStr(motfil));
  21.       sl.Add(FloatToStr(pabkw));
  22.       sl.Add(FloatToStr( uv ));
  23.       ...
  24.       sl.Add(FloatToStr(Rst28));
  25.       sl.Add(FloatToStr(Rst29));
  26.       sl.Add(FloatToStr(Brst25));
  27.       sl.Add(FloatToStr(Rst25));
  28.       Assert(sl.Count=81,'programmer''s error');
  29.       sl.SaveToFile(SaveDialog1.FileName);
  30.       Showmessage('Motor data saved on File');
  31.     finally
  32.       sl.Free;
  33.   end;
  34. end;

jcaser1948

  • Jr. Member
  • **
  • Posts: 68
Re: Problems readig archive files
« Reply #11 on: January 24, 2018, 09:42:29 am »
Try this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.WriteFile;
  2. var
  3.   sl: TStringList;
  4. begin
  5.   if SaveDialog1.Execute then
  6.   begin
  7.     sl:=TStringList.Create;
  8.     try
  9.       sl.Add(dia);
  10.       sl.Add(mes);
  11.       sl.Add(anho);
  12.       sl.Add(motortyp);
  13.       sl.Add(Bearbeiter);
  14.       sl.Add(Statorblechnr);
  15.       sl.Add(Rotorblechnr);
  16.       sl.Add(Angebotsnummer);
  17.       sl.Add(IntToStr(kenrot));
  18.       sl.Add(IntToStr(schltg));
  19.       sl.Add(IntToStr(polzahl));
  20.       sl.Add(IntToStr(motfil));
  21.       sl.Add(FloatToStr(pabkw));
  22.       sl.Add(FloatToStr( uv ));
  23.       ...
  24.       sl.Add(FloatToStr(Rst28));
  25.       sl.Add(FloatToStr(Rst29));
  26.       sl.Add(FloatToStr(Brst25));
  27.       sl.Add(FloatToStr(Rst25));
  28.       Assert(sl.Count=81,'programmer''s error');
  29.       sl.SaveToFile(SaveDialog1.FileName);
  30.       Showmessage('Motor data saved on File');
  31.     finally
  32.       sl.Free;
  33.   end;
  34. end;

Dear HowardPc
I have  reduced your procedure in oder to test it

 
Code: Pascal  [Select][+][-]
  1. PROCEDURE TForm1.WriteFile;
  2. VAR
  3.     sl: TStringList;
  4.    BEGIN
  5.  
  6.     if SaveDialog1.Execute then
  7.           sl:=TStringList.Create;
  8.       Begin
  9.      sl.SaveToFile( SaveDialog1.Filename );
  10.       try
  11.        sl.Add(dia);
  12.       sl.Add(mes);
  13.       sl.Add(anho);
  14.       sl.Add(motortyp);
  15.       sl.Add(Bearbeiter);
  16.       sl.Add(Statorblechnr);
  17.       sl.Add(Rotorblechnr);
  18.       sl.Add(Angebotsnummer);
  19.       sl.Add(IntToStr(kenrot));
  20.       sl.Add(IntToStr(schltg));
  21.       sl.Add(IntToStr(polzahl));
  22.       sl.Add(IntToStr(motfil));
  23.       sl.Add(FloatToStr(pabkw));
  24.       sl.Add(FloatToStr( uv ));
  25.         finally
  26.       sl.Free;
  27.  
  28.     End;
  29.  
  30. END;  
  31. 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}}
  32.  
  33.      
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

  • Hero Member
  • *****
  • Posts: 4144
Re: Problems readig archive files
« Reply #12 on: January 24, 2018, 09:52:10 am »
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.
« Last Edit: January 24, 2018, 09:53:41 am by howardpc »

Handoko

  • Hero Member
  • *****
  • Posts: 5376
  • My goal: build my own game engine using Lazarus
Re: Problems readig archive files
« Reply #13 on: January 24, 2018, 10:26:38 am »
Let's analyze the structure of the code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.WriteFile;
  2. var
  3.   sl: TStringList;
  4. begin
  5.   if SaveDialog1.Execute then
  6.   begin
  7.     sl:=TStringList.Create;
  8.     try
  9.       sl.Add ...
  10.       ...
  11.       Showmessage('Motor data saved on File');
  12.     finally
  13.       sl.Free;
  14.   end;
  15. 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

  • Jr. Member
  • **
  • Posts: 68
Re: Problems readig archive files
« Reply #14 on: January 24, 2018, 11:05:35 am »
Let's analyze the structure of the code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.WriteFile;
  2. var
  3.   sl: TStringList;
  4. begin
  5.   if SaveDialog1.Execute then
  6.   begin
  7.     sl:=TStringList.Create;
  8.     try
  9.       sl.Add ...
  10.       ...
  11.       Showmessage('Motor data saved on File');
  12.     finally
  13.       sl.Free;
  14.   end;
  15. 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

 

TinyPortal © 2005-2018