An aboslute DON'T lazarus / 13-General ---------------------------------------------------------------------- matthijs · 2005-01-19 07:14 I like to give some extra attention to the post from Marc in this topic. Even in de documentation project I see this happening. So maybe it is a good idea to remove the public var declaration from the code generated by Lazarus. The first thing I usually do is removing it anyway, so it won't be possible to use it. ---------------------------------------------------------------------- Marc · 2005-01-19 09:30 I would vote for configurable (if it isn't already the case) Personally I would turn of the var generation ---------------------------------------------------------------------- mikiwoz · 2005-01-19 19:40 Looks like a draw here. I agree - let the users decide for themselves. I have a policy of User Knows Better. Personally, I think Laz was supposed to be a RAD app, wasn't it? So, as public var declaration makes developing an app a bit more rapid, I would like to have it. The best solution, though, is simply to let users decide. P.S. wouldn't adding a "Configurable" option to the poll be a good idea? ---------------------------------------------------------------------- matthijs · 2005-01-20 04:36 Quote from: "mikiwoz"Looks like a draw here. P.S. wouldn't adding a "Configurable" option to the poll be a good idea? I would like to, but it is not possible to add or change an poll option! ---------------------------------------------------------------------- mikiwoz · 2005-01-20 08:02 I thought that moderators and the topic's author actually CAN change the poll options... ---------------------------------------------------------------------- Vincent Snijders · 2005-01-20 10:21 Matthijs, you can edit your first post. Then you add another poll option. I just tested it with the releases poll. :-). ---------------------------------------------------------------------- Vincent Snijders · 2005-01-20 11:56 Hmm, once somebody has voted it can't be changed anymore. :-( ---------------------------------------------------------------------- fatg · 2005-01-20 23:34 maybe you should count the 'I don`t care' vote as 'As each prefers', which is kind of 'Configurable' Otherwise, isn't delphi working the same way, making a form public var? I'd like to hear some pros and cons, but the way I see it, the form is just another instance of a class and as such it should have a kind of a handle. Other classes, the ones that users create on their own, have such handles. Also the classes inside the form do. Why should the form be special? Or did I get something utterly wrong? ---------------------------------------------------------------------- Marc · 2005-01-21 10:20 There is nothing wrong with having a var to store your instance.  You only have to think when to use it. More than once I've seen situations where the var is used inside a class to modify it. For a single instance it most times works, not for multiple. For me personally I would like to be in control when, how and howmany forms are created, so the first thing I do in delphi is remove the global var (you can't accidetally refer to it and it doesn't get accidently created). ---------------------------------------------------------------------- matthijs · 2005-01-21 11:50 The reason for removing the global vars from the unit is this: Have a look at this code: Code: [Select] procedure TtrymysqlForm1.ConnectButtonClick(Sender: TObject); (* Connect to MySQL using user data from Text entry boxes on Main Form *) var strg: string;   begin    dummy1 :=  trymysqlForm1.HostEdit.text+#0;    host := @dummy1[1];    dummy2 := trymysqlForm1.UserEdit.text+#0;    user := @dummy2[1] ;    dummy3 := trymysqlForm1.PasswdEdit.text+#0;   passwd := @dummy3[1] ;   //etc (Code taken from Lazarus Documentation Project This code will compile fine. But what happens if you do something like: Code: [Select] begin   MySqlForm := TTrymysqlform.Create(self)   try     MySQLForm.ShowModal;   finally     MySQLForm.Free;   end; end; As soon as the button is pressed there will be an access violation, because trymysqlform1 is not created. If you remove the global variable you will not be able to use it in the implementation. Thus the AV will not happen when you use another variable to store your form-instance in. I tutor starters, and see this mistake happen a lot. I know it can be easily avoided by using self, but why not remove the temptation. I know Delphi creates the var as well, but that is no argument to keep doing this in Lazarus. ---------------------------------------------------------------------- RudieD · 2005-01-21 15:08 Just use Self (pointer to current instance). procedure TtrymysqlForm1.ConnectButtonClick(Sender: TObject); (* Connect to MySQL using user data from Text entry boxes on Main Form *) var strg: string;   begin    dummy1 :=  Self.HostEdit.text+#0;    host := @dummy1[1];    dummy2 := Self.UserEdit.text+#0;    user := @dummy2[1] ;    dummy3 := Self.PasswdEdit.text+#0;   passwd := @dummy3[1] ;   //etc ---------------------------------------------------------------------- matthijs · 2005-01-21 16:26 Quote from: "RudieD"Just use Self (pointer to current instance). That is not the point, I allready said so in my previous post. The point is: By providing the variable, the mistake is made rather often, certainly by people who just started using Delphi or Lazarus. And it creates a bug which is hard to crack as well. ---------------------------------------------------------------------- fatg · 2005-01-21 21:19 How about refering to a particular form from outside of the form? How can, for example, about box refer to main form of the program (which is definetly created)? ---------------------------------------------------------------------- Anonymous · 2005-01-22 10:59 That is not that difficult. The about box knows about the application it belongs to, and the application knows about its mainform. So if you want to do something from another form in the mainform just look for Application.Mainform. In other cases, for instance dialogs created by an event from some form: create the dialog with owner the form which creates it. In that way you know who the owner is and you can check its type and then cast it. I cannot think of any other cases, if you have them you might have to reconsider your application logic. Object orientation is all about not knowing what a object doesnot need to know! ---------------------------------------------------------------------- matthijs · 2005-01-22 11:53 Obviously I was not logged in. For 'application logic' read 'application design' in the post above.