[Lazarus-es] Error en funci?n while

Ismael L. Donis García ismael en citricos.co.cu
Lun Nov 23 19:24:26 CET 2009


1ro No tengo acceso a Internet: por lo que no puedo buscar por esa vía.

2do Se que while es una palabra reservado de muchos lenguajes de programación: pero cuando digo función while me refiero a la acción que hace while dentro del lenguaje que en difinitiva debe ser una función interna del lenguaje.

3ra te copio textual lo que dice el archivo rtl.pdf que me hizo llegar un miebro de la lista que lamentablemente no recuerdo ahora quien fue.

36.9.25 Break

Synopsis: Exit current loop construct.

Declaration: procedure Break

Visibility: default

Description: Break jumps to the statement following the end of the current repetitive statement. The code

between the Break call and the end of the repetitive statement is skipped. The condition of the

repetitive statement is NOT evaluated.

This can be used with For, var{repeat} and While statements.

Note that while this is a procedure, Break is a reserved word and hence cannot be redefined.

Errors: None.

See also: Continue (1234), Exit (1246)

Listing: ./refex/ex87.pp

4to Acabo de probar con la (palabra reservada) continue y también da error al entrar en el while.

En otro mensaje mando la imagen del error para que veas.

Saludos
=========
|| ISMAEL ||
=========
----- Mensaje original ----- 
  De: Raistware 
  Para: Spanish version of Lazarus List 
  Enviado: lunes, 23 de noviembre de 2009 10:41
  Asunto: Re: [Lazarus-es] Error en funci?n while


  Ismael L. Donis Garc?a escribió: 
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.
  
  Saludos:
  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, while no es ninguna función, es una palabra reservada, algo drásticamente distinto.
  'break' funciona para 'romper' bucles, en C y derivados. En pascal 'break', que yo recuerde, solo tiene uso en un case ... of. Para bucles se utiliza 'Continue', que lo que hace es continuar con el siguiente. En tu ejemplo, un simple continue te basta, puesto que ya has puesto una de las condiciones en el while para que salga: bolhenc <> false


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.

  



------------------------------------------------------------------------------


  _______________________________________________
  Lazarus-es mailing list
  Lazarus-es en lists.lazarus.freepascal.org
  http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus-es
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus-es/attachments/20091123/eaf802d5/attachment-0002.html>


More information about the Lazarus-es mailing list