Help lazarus / 13-General ---------------------------------------------------------------------- benwin · 2008-05-26 23:03 Hello, i am starting on lazarus, but i only have uses pascal...I dont know were is my error, and i like if possible, then somebody help-me with examples, or help-me with my code. Sory about my english  :oops:...   http://phpfi.com/319911 or unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,   StdCtrls; type   { TForm1 }   TForm1 = class(TForm)     Btconverter: TButton;     Button1: TButton;     BtSequencia: TButton;     EditSequencia: TEdit;     Editconversao: TEdit;     GroupBox1: TGroupBox;     GroupBox2: TGroupBox;     GroupBox3: TGroupBox;     Image1: TImage;     Image2: TImage;     Label1: TLabel;     Label2: TLabel;     Label3: TLabel;     Label4: TLabel;     Panel1: TPanel;     ToggleBox1: TToggleBox;     procedure BtconverterClick(Sender: TObject);     procedure BtSequenciaClick(Sender: TObject);     procedure EditSequenciaChange(Sender: TObject);     procedure EditconversaoChange(Sender: TObject);     procedure GroupBox1Click(Sender: TObject);     procedure Image3Click(Sender: TObject);     procedure ListBox1Click(Sender: TObject);     procedure ToggleBox1Change(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1;   oct : array[1..5] of real;   dec, calc, parti : real;   x:ansistring;   j : integer; implementation { TForm1 } procedure TForm1.Image3Click(Sender: TObject); begin end; procedure TForm1.ListBox1Click(Sender: TObject); begin end; procedure TForm1.ToggleBox1Change(Sender: TObject); begin   Close; end; procedure TForm1.GroupBox1Click(Sender: TObject); begin end; procedure TForm1.BtconverterClick(Sender: TObject); begin readln(dec); end; procedure TForm1.BtSequenciaClick(Sender: TObject); begin end; procedure TForm1.EditSequenciaChange(Sender: TObject); begin end; procedure TForm1.EditconversaoChange(Sender: TObject); begin if (dec>0) and (dec<1) then   begin      repeat      calc:=dec*8;      parti:=int(calc);      dec:=frac(calc);      oct[j]:=parti;      j:=j+1;      until (j=5); end;    ShowMessage(oct[j]); end; initialization   {$I unit1.lrs} end. ---------------------------------------------------------------------- theo · 2008-05-27 00:42 What is the Error? I see only a problem in ShowMessage(oct[j]); replace with: ShowMessage(FloatToStr(oct[j])); ---------------------------------------------------------------------- benwin · 2008-05-27 02:11 hi, tanks for the help. But when i compile and run my project, and click on the edit box (TForm1.BtconverterClick) the program return with this event: File not Open Press Ok to ignore and risk data corruption Press cancel to kill the program. .... and when lazarus is compiling the program, he asked for the file "system.inc" and asked if i want to locate this file... Anyway tanks... ---------------------------------------------------------------------- benwin · 2008-05-27 02:18 If you want to see better my problem, here i upload all the arquives and the executable... http://www.box.net/shared/0mbb9mdwck ---------------------------------------------------------------------- Leledumbo · 2008-05-27 03:57 You're creating GUI application (check Project->Compiler Options->Linking), while readln are meant to read from stdin. When creating GUI apps, fpc doesn't open stdin for reading (and stdout for writing, too). ---------------------------------------------------------------------- benwin · 2008-05-27 20:30 So, what i do to read the variable from question, and show the results to user? tanks... ---------------------------------------------------------------------- Yurgel · 2008-05-27 22:26 For GUI Application: Place on the form TEdit control - Edit1 and TButton - Button1. In OnClick event of Button1 write something like Code: [Select] ... var   oct : array[1..5] of real;   dec, calc, parti : real;   x:ansistring;   j : integer; begin   dec := StrToFloat (Edit1.Text);   if (dec>0) and (dec<1) then     repeat       calc:=dec*8;       parti:=int(calc);       dec:=frac(calc);       oct[j]:=parti;       j:=j+1;     until (j=5);     ShowMessage(FloatToStr (oct[j])); end; Here user is supposed to enter value of "dec" in Edit1 control on the form, press Button1 and he will see result. ----------- Console Application: Start in Lazarus' menu "File/New/Console Application", and add your code in DoRun method of TApplication class. You'll have something like this: Code: [Select] program project1; {$mode objfpc}{$H+} uses   {$IFDEF UNIX}{$IFDEF UseCThreads}   cthreads,   {$ENDIF}{$ENDIF}   Classes, SysUtils, CustApp   { you can add units after this }; type   { TMyApplication }   TMyApplication = class(TCustomApplication)   protected     procedure DoRun; override;   public     constructor Create(TheOwner: TComponent); override;     destructor Destroy; override;     procedure WriteHelp; virtual;   end; { TMyApplication } procedure TMyApplication.DoRun; var   ErrorMsg: String;   oct : array[1..5] of real;   dec, calc, parti : real;   j : integer; begin   // quick check parameters   ErrorMsg:=CheckOptions('h','help');   if ErrorMsg<>'' then begin     ShowException(Exception.Create(ErrorMsg));     Halt;   end;   // parse parameters   if HasOption('h','help') then begin     WriteHelp;     Halt;   end;   { add your program here }   j := 0;   Write ('Dec = ?: ');   ReadLn (dec);   if (dec>0) and (dec<1) then     repeat       calc:=dec*8;       parti:=int(calc);       dec:=frac(calc);       oct[j]:=parti;       j:=j+1;     until (j=5);   WriteLn ('Result = ', oct[j]);   WriteLn ('Press Enter...');   ReadLn;   // stop program loop   Terminate; end; constructor TMyApplication.Create(TheOwner: TComponent); begin   inherited Create(TheOwner);   StopOnException:=True; end; destructor TMyApplication.Destroy; begin   inherited Destroy; end; procedure TMyApplication.WriteHelp; begin   { add your help code here }   writeln('Usage: ',ExeName,' -h'); end; var   Application: TMyApplication; begin   Application:=TMyApplication.Create(nil);   Application.Title:='My Application';   Application.Run;   Application.Free; end. Under Linux you'll have to open BASH$ or any other shell, find your file, and run it. It may not work under IDE, although i'm not sure. Result will look like: Code: [Select] [root@Rover Test]# ./project1 Dec = ?: .9 Result =  6.116648415405354E-270 Press Enter... [root@Rover Test]# Can't say how Lazarus works with console applications under W32, theoretically you can launch them directly from IDE. ---------------------------------------------------------------------- Yurgel · 2008-05-27 22:39 Quote from: "theo"What is the Error? I see only a problem in ShowMessage(oct[j]); replace with: ShowMessage(FloatToStr(oct[j])); actually, there is at least one more problem - variable J had never been initialized, but is used like array index though. In most cases it will be equal to zero by default, but this can vary depending upon a lot of things. ---------------------------------------------------------------------- Leledumbo · 2008-05-28 08:38 Or in easier way: InputBox