<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-15"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Ismael L. Donis Garc?a escribió:
<blockquote cite="mid:0DB8BE9F46FC4627BA11E00B18F75A57@desarrollo"
 type="cite">
  <pre wrap="">He estado todo este fin de semana atascado en un error que me da la función 
while, he tratado por todas las vías que conozco y no he podido solucionar 
el problema.
  </pre>
</blockquote>
<br>
Saludos:<br>
Lo primero, busca un poco por internet tutoriales básicos de Pascal, en
especial referente a bucles, porque tienes un lio que no te enteras. Lo
segundo, <b>while</b> no es ninguna función, es una palabra reservada,
algo drásticamente distinto.<br>
'<b>break</b>' funciona para 'romper' bucles, en C y derivados. En
pascal '<b>break</b>', que yo recuerde, solo tiene uso en un <b>case
... of</b>. Para bucles se utiliza '<b>Continue</b>', que lo que hace
es continuar con el siguiente. En tu ejemplo, un simple <b>continue </b>te
basta, puesto que ya has puesto una de las condiciones en el while para
que salga: bolhenc <> false<br>
<br>
<blockquote cite="mid:0DB8BE9F46FC4627BA11E00B18F75A57@desarrollo"
 type="cite">
  <pre wrap="">Al ejecutar la función while en una función que a la ves es llamada por otra 
función y que esta otra función es llamada por un evento, me ocurre el 
error.

Le adjunté en otro mensaje un proyecto de ejemplo pero fue retenido, el 
mismo tenía sintise del error para ver si me
pueden ayudar o es algún error del lazarus o del fpc.

Por lo que copio y pego el código del formulario para que pueda ser 
revisado, es un formulario con 1 boton.

unit uprueba;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, 
Dialogs,
  StdCtrls, StrUtils;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
    function datos(): Boolean;
  public
    { public declarations }
    function IniExistHead(fileini: string; head: string): boolean;
  end;

var
  Form1: TForm1;

implementation

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
  var
    fileini: String;
begin
  {$IFDEF UNIX}
    fileini := GetEnvironmentVariable ('HOME') + '/mprima.ini';
  {$ELSE}
    fileini := ExtractFilePath (Application.Exename) + 'mprima.ini';
  {$ENDIF}
  if datos () then
    begin
      Showmessage ('El archivo ya existía');
      Showmessage (fileini);
    end
  else
    Showmessage ('El archivo fue creado');
end;

procedure TForm1.FormShow(Sender: TObject);
begin
 Button1Click(sender);
end;

function TForm1.datos(): Boolean;
  var
    fileini: String;
    logfile: TFileStream;
begin
  {$IFDEF UNIX}
    fileini := GetEnvironmentVariable ('HOME') + '/mprima.ini';
  {$ELSE}
    fileini := ExtractFilePath (Application.Exename) + 'mprima.ini';
  {$ENDIF}
  if FileExists (fileini) then
    if IniExistHead(fileini, 'Datos') = false then
      result := false
    else
      result := true
  else
    begin
      logfile := TFileStream.Create (fileini, fmCreate or fmOpenReadWrite);
      logfile.free;
      result := false;
    end;
end;

function TForm1.IniExistHead(fileini: string; head: string): boolean;
  var
    bolhenc: boolean;
    strlinea, strhead: string;
    oldfileini: TextFile;
begin
  bolhenc := false;
  AssignFile (oldfileini, fileini);
  Append (oldfileini); // abre un archivo existente

  showmessage ('Punto 1');

  while (not bolhenc) and (not eof(oldfileini)) do
    begin

  showmessage ('Punto 2');

      readln(oldfileini, strlinea);
      strlinea := trim(strlinea);
      if strlinea <> '' then
        if leftstr(strlinea, 1) <> ';' then
          if strlinea = strhead then
            begin
              bolhenc := true; // al documentar la proxima linea el error se 
da aquí
              //break; // si descomento esta linea me da error aqui
            end;
    end;
  closefile(oldfileini);
  result := bolhenc;
end;

initialization
  {$I uprueba.lrs}

end.

  </pre>
</blockquote>
<br>
</body>
</html>