Console programs vs GUI programs - zeos lazarus / 13-General ---------------------------------------------------------------------- chrnobel · 2006-11-10 13:50 Hi. Can anybody help me, I am properly lacking some basic understanding of Lazarus. I am trying to make a console database application using Lazarus / Zeos. The environment is Ubuntu6.06, Laz 0.9.18 (deb) installed out of the box, zeos unpacked to a zeos library under my homedir, and the Lazarus package installed  - no problem, everything works. I can then make a Lazarus application like this: unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,   ZConnection, ZDataset, DB, DBGrids, Buttons, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)     Button1: TButton;     Datasource1: TDatasource;     DBGrid1: TDBGrid;     Memo1: TMemo;     ZConnection1: TZConnection;     ZQuery1: TZQuery;     procedure Button1Click(Sender: TObject);     procedure DBGrid1CellClick(Column: TColumn);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1;   sqlsentence: TstringList; implementation { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin   ZConnection1.Protocol:='mysql-5';   ZConnection1.HostName:='localhost';   ZConnection1.Port:=3306;   ZConnection1.Database:='testdb';   ZConnection1.User:='cn';   ZConnection1.Password:='blabla';   ZConnection1. Connected:=true;   sqlsentence:=TstringList.Create;   sqlsentence.Add('Select * from FPdev');   ZQuery1.SQL:=sqlsentence;   ZQuery1.Active:=true; end; procedure TForm1.DBGrid1CellClick(Column: TColumn); begin   DataSource1.DataSet.First;   While not DataSource1.DataSet.EOF do   begin     Memo1.Lines.Add(DataSource1.DataSet.FieldByName('UserName').AsString);     DataSource1.DataSet.Next;   end; end; initialization   {$I unit1.lrs} end. Works without problems, I can connect to the database etc. However if I just try to make a console application like this: program project1; {$mode objfpc}{$H+} uses   {$IFDEF UNIX}{$IFDEF UseCThreads}   cthreads,   {$ENDIF}{$ENDIF}   Classes, ZConnection, ZDataset, DB   { add your units here };   var   ZConnection1: TZConnection;   Datasource1: TDatasource;   ZQuery1: TZQuery;   sqlsentence: TstringList; begin   ZConnection1.HostName:='localhost';   ZConnection1.Port:=3306;   ZConnection1.Database:='testdb';   ZConnection1.User:='cn';   ZConnection1.Password:='blabla';   ZConnection1.Connected:=true;   ZConnection1.Protocol:='mysql-5';   sqlsentence:=TstringList.Create;   sqlsentence.Add('Select * from FPdev');   ZQuery1.Connection:=ZConnection1;   ZQuery1.SQL:=sqlsentence;   ZQuery1.Active:=true;   DataSource1.DataSet:=ZQuery1;   DataSource1.DataSet.First;   While not DataSource1.DataSet.EOF do   begin     WriteLn(DataSource1.DataSet.FieldByName('UserName').AsString);     DataSource1.DataSet.Next;   end; end. Life becomes difficult. It (thats where my lack of knowledge comes in) seems like the editor is not aware of the existance of Zeos anymore, so if trying to use code completion (ctrl-space) the IDE returns with unit (eg. ZConnection) not found. Hmm, so Lazarus behaves differently when I am making console applications. Trying to compile does not work either - hmmm. Including this line in fpc.cfg: -Fu/home/cn/zeos/packages/lazarus/build makes it possible to compile, but the program crashes. Also code completion does still not work. So what am I doing wrong? Christian ---------------------------------------------------------------------- Vincent Snijders · 2006-11-10 15:13 Instead of adding -Fu/home/cn/zeos/packages/lazarus/build  to the fpc.cfg, you should add the packages to projects requirements in the project inspector. In Form-Application this is done automatically as soon as you drop a ZEOS component on a form. I don't use ZEOS, so I don't know why it crashes. ---------------------------------------------------------------------- chrnobel · 2006-11-12 00:01 Hi. "In Form-Application this is done automatically as soon as you drop a ZEOS component on a form. " Yes, but the problem is that I am going to make a console application, so I do not have any form (and therefore neither the object inspector). Christian ---------------------------------------------------------------------- Zorba · 2006-11-12 02:21 Hi Christian Not sure if you understood Vincent's reply. Vincent said Project Inspector, which is not the same as Object Inspector that you mentioned. Maybe I understood wrong from your post, but since you don't mention Project Inspector, I figured I can mention it in case you read the reply from Vincent too fast. If I understood wrong then please disregard my reply. ---------------------------------------------------------------------- chrnobel · 2006-11-12 17:04 Ahh, thanks, and sorry. Yes, I misunderstood Vincent's reply, I aplogize. I have included the zcomponents as a required package in the Project Inspector, and now code completion works, and I can compile the project. However it still crashes with an access violation, so I have to play a little more with it. Christian ---------------------------------------------------------------------- chrnobel · 2006-11-12 22:11 Okay, got it now. I have to create the following:   ZConnection1:=TZConnection.Create(nil);   Datasource1:=TDatasource.Create(nil);   ZQuery1:=TZQuery.Create(nil); The trick with the Project Inspector made it much easier for me to play with, so thanks to Vincent and Zorba for leading me in the right direction. And I also would like to say a big thanks to you guys for making Lazarus - it is really really cool, I am phasing Delphi out in favour of Lazarus, and day by day I miss Delhpi less and less. Regards Christian ---------------------------------------------------------------------- JimBodkins · 2006-11-24 04:47 As a tangential question, is there a mode (code generation) which would gracefully handle the use of uninitialized pointers as in the above example? My primary experience has been (over the years) C. If you have written large systems using C, you must appreciate strongly typed languages. I do. I would gladly pay a small performance price to permanently eliminate SEGV's. (Access violations - uninitialized pointer usage). Sorry for the piggy backed question. Jim ---------------------------------------------------------------------- RudieD · 2006-12-01 12:50 Do you mean somthing like Code: [Select] if Assigned(MyVar) then ? ---------------------------------------------------------------------- JimBodkins · 2006-12-01 19:25 No, something more like bounds checking. Something (with a little overhead) that would avoid the use of unititialized pointers. Which are all too common. If I never see another Segv it will be too soon. ---------------------------------------------------------------------- Vincent Snijders · 2006-12-03 12:55 Maybe that is what -Cp does. See: http://freepascal.org/docs- html/prog/progsu6.html ---------------------------------------------------------------------- JimBodkins · 2006-12-03 22:51 Thank you very much