Italian community of Lazarus and Free Pascal

Programmazione => Generale => Topic aperto da: ivanomonti - Dicembre 12, 2011, 11:53:43 am

Titolo: if then e testament
Inserito da: ivanomonti - Dicembre 12, 2011, 11:53:43 am
ecco il primo codice che non trova soluzione seguendo le linee guida :-), un aiuto grazie.

procedure TForm1.Timer1Timer(Sender: TObject);
begin

     Timer1.Interval:=100; // poi posto in open di form
     Timer1.Enabled:=true; // poi posto in open di form

     if ProgressBar1.Position > 100 then
     begin
       ProgressBar1.Position = 0
     end
     else
     begin
       ProgressBar1.Position=ProgressBar1.Position+1
     end;

end;
Titolo: Re:if then e testament
Inserito da: xinyiman - Dicembre 12, 2011, 12:02:24 pm
Guarda quello che segue è il codice intero per fare quello che volevi. Per prima cosa, l'assegnazione viene fatta con il := e non solo con =

Altra cosa se ometti il begin e end dalle if allora puoi non mettere il ; a fine riga. Diversamente è obbligatorio.

Poi devi valorizzare l'intervall fuori dall'evento del timer perchè è l'interval>0 che vvia l'uso del timer. Spero di esserti stato d'aiuto.

Codice: [Seleziona]
unit Unit1; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  ComCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    ProgressBar1: TProgressBar;
    Timer1: TTimer;
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Timer1Timer(Sender: TObject);
begin
       if ProgressBar1.Position > 100 then
       begin
         ProgressBar1.Position:=0;
       end
       else
       begin
         ProgressBar1.Position:=ProgressBar1.Position+1;
       end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
     Timer1.Interval:=100; // poi posto in open di form
end;

end.
Titolo: Re:if then e testament
Inserito da: ivanomonti - Dicembre 12, 2011, 12:21:25 pm
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if ProgressBar1.Position > 100 then
  begin
    ShowMessage( '100' );
    ProgressBar1.Position:=0;
  end
  else
  begin
    ProgressBar1.Position:=ProgressBar1.Position+1;
  end;
end;

così il compilatore va avanti, ma if non scatta .... come posso monitorare int come stringa esempio form.text = str(ProgressBar1.Position) or ProgressBar1.Position.Tostring() o come ???
Titolo: Re:if then e testament
Inserito da: ivanomonti - Dicembre 12, 2011, 12:52:15 pm
scoperto l'errore

ProgressBar1.max:=100

if ProgressBar1.Position > 100 then // non sarà mai suoperiore a 100 :-) che bigul che sono hahahah

scusate lo sfogo.
Titolo: Re:if then e testament
Inserito da: xinyiman - Dicembre 12, 2011, 01:25:55 pm
Bene, vuol dire che hai risolto :)