Re: [Gambas-user] static const?

2010-04-14 Thread Doriano Blengino
Fabián Flores Vadell ha scritto:
 2010/4/13 Jussi Lahtinenjussi.lahti...@gmail.com:

 Just in case:

 REPEAT
  b = TabStrip3.Count ' In fact, this does nothing usefull
  INC a
 UNTIL a  TabStrip3.Count OR TabStrip3[a].Caption = IdCaption

   This doesn't make same functionality.
  
I can't resist to add my mis-contribute...

Back to the beginning: a CONST declaration is something that uses no 
memory, so it can not have instances, and hence it can not be STATIC. 
The C language, in facts, does not even have CONSTs - it goes with 
#define. So, it would be correct to forbid STATIC when declaring CONSTs. 
On the other hand, a CONST is always static, because the effective data 
it describes reside in a memory outside the program - they reside in the 
compiler memory.

About the cycles WHILE, FOR, REPEAT and so on, I think the statements 
BREAK and CONTINUE are very useful (I would add a third statement: 
RESTART): they permit a finer control and many times they are clearer 
than complex tests. . Your example only has two test, against COUNT and 
the CAPTION. What kind of test would you write if the conditions were 
15? Perhaps concatenated (I mean, some test are only meaningful when 
other conditions are met).

Finally, your last lines of code do not work:
 PRIVATE FUNCTION ScanTab(IdCaption AS String) AS Byte
 DIM a AS Byte = 0

WHILE (a  TabStrip1.Count - 1) AND (TabStrip1[a].Text  IdCaption)
  INC a
WEND

RETURN IF(TabStrip1[a].Caption = IdCaption, a, -1)
 END

Suppose you have a tabstrip with three tabs, and last, Tabstrip1[2] has 
the caption we want.
In the first cycle, we test Tabstrip1[0]: does not match, and a turns 1
In the secon cycle, we test tabstrip1[1]: does not match and a turns 2
The third cycle does not get executed - a is 2, which is not less than 
3-1 (it is equal).

Moreover, your algorithm does a double test on caption, which could be 
avoided. Doing an additional test is not an important thing if the test 
is quick and the routine is called not too much often. What if the 
routine is called millions time, or the test is more heavy?

About not using RETURN or BREAK inside cycles, we must think at 
different kind of cycles. The WHILE and alike, where no variables are 
directly involved in the cycle declaration, never have problems - the 
semantic of the declaration does not imply anything about variable 
allocation. In the FOR cycles instead, other languages can do strange 
things, both on allocation and code optimization, so it is effectively a 
bad idea to fiddle with the loop control variable; in other languages 
this is not stressed the same way (basic, for example), but actually is, 
at least, ugly.

It seems to me that you have said that an exception would be the FOR 
EACH cycle... why?

Regards,
Doriano


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Showing the Form's Gui

2010-04-14 Thread Jorge Carrión
Ricardo:
Could you post a example of your open forms method? I'm very interested on
it. It sound like something I have searching for a long time.

Gracias

Jorge


2010/4/13 Ricardo Díaz Martín oceanosoftlapa...@gmail.com

 If It can help to someone, this is I always do:

 When I'm going to open a form, I always call my own OpenForm(FormName as
 String, Parameters as String) sub. This sub is not inside the form I'm
 going
 to open. It's a public sub that's is inside a utilities module.

 OpenForm() sub create new object with the form (f.e. FRMMain) and put its
 reference inside a public collection called OpenedForms. Before to show
 form
 to the user, I show other form with a progress bar and a label showing
 Loading... and I'm going executing SQL, show/hid controls, etc... with no
 show anything. If there are a fixed steps to data load, I updated progress
 bar and when load process finish I show the form.

 I use this in all my apps (since lot of years when I never eared about
 gambas and I was programing in VB, Access, Java, etc...) and for me is the
 best option. For sure there is a lot of ways to do this.

 Regards,
 Ricardo Díaz



 2010/4/13 Doriano Blengino doriano.bleng...@fastwebnet.it

  Fabien Bodard ha scritto:
   2010/4/13 Doriano Blengino doriano.bleng...@fastwebnet.it:
  
   Fabien Bodard ha scritto:
  
   just remember to put a flag to say when the data are loaded !
  
  
   What would be the reason for this flag?
  
   if the form is showed and the data not accessible ?
  
  Really, there could be a problem if the user clicks a button 50 ms after
  the button (and the whole form) is visible. A remote possibility, and
  application-dependent. But I know users enough to imagine that someone
  could do it... :-)
 
  Reducing the interval of the one-shot timer can help, but does not solve
  (interval=0 could?). The better way is to disable actions the user could
  do with invalid data (application dependent: who says that the form is
  intended to receive clicks?), and perhaps add a nice label stating
  Loading data, please wait... and so on.
 
  Anyway, the flag is the worse solution. Supposing you use a flag, and
  the user clicks or types too fast, what would you do? A
  Message.Info(You clicked too fast. Go to have a coffee and come back
  later.)? :-) Better to disable some controls, so the user is informed
  before; in addition, controls are already global variables which carry
  informations with them. Well, this is my opinion - I hate to duplicate
  informations around, but someone else on this list, time ago, said
  never use the GUI to store information. The problem with global (or
  class) variables is that you can forget them more easily than some
  property of a visible control.
 
  Regards,
  Doriano
 
 
 
 
 --
  Download Intel#174; Parallel Studio Eval
  Try the new software tools for yourself. Speed compiling, find bugs
  proactively, and fine-tune applications for parallel performance.
  See why Intel Parallel Studio got high marks during beta.
  http://p.sf.net/sfu/intel-sw-dev
  ___
  Gambas-user mailing list
  Gambas-user@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/gambas-user
 

 --
 Download Intel#174; Parallel Studio Eval
 Try the new software tools for yourself. Speed compiling, find bugs
 proactively, and fine-tune applications for parallel performance.
 See why Intel Parallel Studio got high marks during beta.
 http://p.sf.net/sfu/intel-sw-dev
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Showing the Form's Gui

2010-04-14 Thread Caveat
Hi Jorge,

While we wait to see if Ricardo wants to share his open forms method
(I'm also interested to see it), here's some code I have used before
(see attachment) where the opening/closing of forms is handled by a
module, which I've called RunController.

The module is set as the Startup Class (normally that's by default the
first Form you declare I think) and must have a Main() method.
Right-clicking on the module brings up a context menu where you can
click on the Startup Class checkbox.

You can see that the RunController module can decide when it opens each
form (so you could have some long-running data extraction go on in the
background), and handles events raised by the forms (in conjunction with
Attach, making sure RunController actually gets the events).

One of the first things RunController does is to decide should I first
open up the settings form (no Dragons defined yet)? or should I show
the main form already (at least one Dragon exists in settings)?:

  IF theSettings.getDragonCount() = 0 THEN
settingsFrm = NEW SettingsForm
settingsFrm.Show
Object.Attach(settingsFrm, ME, SettingsFrm)
  ELSE
Logger.logMessage(RunController.Main() dragon found, so starting
Remote Control, FALSE)
remC = NEW RemoteControl
remC.Show
Object.Attach(remC, ME, Remote)
tCop = NEW TrafficCop
tCop.show
Object.Attach(tCop, ME, Cop)
  END IF

One limitation of my approach is that you need to explicitly declare
each form you're going to use up-front, so I'm interested to see if
Ricardo's approach avoids that.

Regards,
Caveat



On Wed, 2010-04-14 at 11:59 +0200, Jorge Carrión wrote:
 Ricardo:
 Could you post a example of your open forms method? I'm very interested on
 it. It sound like something I have searching for a long time.
 
 Gracias
 
 Jorge
 
 
 2010/4/13 Ricardo Díaz Martín oceanosoftlapa...@gmail.com
 
  If It can help to someone, this is I always do:
 
  When I'm going to open a form, I always call my own OpenForm(FormName as
  String, Parameters as String) sub. This sub is not inside the form I'm
  going
  to open. It's a public sub that's is inside a utilities module.
 
  OpenForm() sub create new object with the form (f.e. FRMMain) and put its
  reference inside a public collection called OpenedForms. Before to show
  form
  to the user, I show other form with a progress bar and a label showing
  Loading... and I'm going executing SQL, show/hid controls, etc... with no
  show anything. If there thrownare a fixed steps to data load, I updated 
  progress
  bar and when load process finish I show the form.
 
  I use this in all my apps (since lot of years when I never eared about
  gambas and I was programing in VB, Access, Java, etc...) and for me is the
  best option. For sure there is a lot of ways to do this.
 
  Regards,
  Ricardo Díaz
 
 
 
  2010/4/13 Doriano Blengino doriano.bleng...@fastwebnet.it
 
   Fabien Bodard ha scritto:
2010/4/13 Doriano Blengino doriano.bleng...@fastwebnet.it:
   
Fabien Bodard ha scritto:
   
just remember to put a flag to say when the data are loaded !
   
   
What would be the reason for this flag?
   
if the form is showed and the data not accessible ?
   
   Really, there could be a problem if the user clicks a button 50 ms after
   the button (and the whole form) is visible. A remote possibility, and
   application-dependent. But I know users enough to imagine that someone
   could do it... :-)
  
   Reducing the interval of the one-shot timer can help, but does not solve
   (interval=0 could?). The better way is to disable actions the user could
   do with invalid data (application dependent: who says that the form is
   intended to receive clicks?), and perhaps add a nice label stating
   Loading data, please wait... and so on.
  
   Anyway, the flag is the worse solution. Supposing you use a flag, and
   the user clicks or types too fast, what would you do? A
   Message.Info(You clicked too fast. Go to have a coffee and come back
   later.)? :-) Better to disable some controls, so the user is informed
   before; in addition, controls are already global variables which carry
   informations with them. Well, this is my opinion - I hate to duplicate
   informations around, but someone else on this list, time ago, said
   never use the GUI to store information. The problem with global (or
   class) variables is that you can forget them more easily than some
   property of a visible control.
  
   Regards,
   Doriano
  
  
  
  
  --
   Download Intel#174; Parallel Studio Eval
   Try the new software tools for yourself. Speed compiling, find bugs
   proactively, and fine-tune applications for parallel performance.
   See why Intel Parallel Studio got high marks during beta.
   http://p.sf.net/sfu/intel-sw-dev
   ___
   Gambas-user mailing list
   Gambas-user@lists.sourceforge.net
   

Re: [Gambas-user] static const?

2010-04-14 Thread Les Hardy


 The C language, in facts, does not even have CONSTs - it goes with 
 #define. So, it would be correct to forbid STATIC when declaring CONSTs.
Surely this is not correct. ANSI C uses const, and C++ also uses the 
const keyword.
#define (a preprocessor directive) is a relic from old C, and const is 
now recommended use instead.

Also, it would be correct to use static with const, the line below would 
be correct use.

static const int daysPerMonth[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};


Having said that, The original question was not about C,  I think Fabian 
was simply asking about the scope of constants in classes (in Gambas)


Regards
Les Hardy

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-14 Thread Doriano Blengino
Les Hardy ha scritto:

 The C language, in facts, does not even have CONSTs - it goes with
 #define. So, it would be correct to forbid STATIC when declaring CONSTs.
  
 Surely this is not correct. ANSI C uses const, and C++ also uses the
 const keyword.
 #define (a preprocessor directive) is a relic from old C, and const is
 now recommended use instead.

Surely, according to http://www.ericgiguere.com/articles/ansi-c-summary.html
 The declaration:
  enum colours { RED, BLUE, GREEN };


 would declare colours as an enumeration tag representing the integer 
 constants RED, BLUE and GREEN. These enumeration constants are given 
 integer values starting at 0 and increasing by 1 with each identifier.

 An enumeration constant may be used wherever an integer is expected. 
 The following is equivalent to the above enumerated type:

  #define RED   0
  #define BLUE  1
  #define GREEN 2


Moreover, from http://tigcc.ticalc.org/doc/keywords.html


 _const_

 *Makes variable value or pointer parameter unmodifiable.*

 When |const| is used with a variable, it uses the following syntax:

 const/variable-name/  [ =/value/];


 In this case, the |const| modifier allows you to assign an initial 
 value to a variable that cannot later be changed by the program. For 
 example,

 const my_age = 32;


 Any assignments to |'my_age'| will result in a compiler error. 
 However, such declaration is quite different than using

 #define my_age 32

 In the first case, the compiler allocates a memory for |'my_age'| and 
 stores the initial value 32 there, but it will not allow any later 
 assignment to this variable. But, in the second case, all occurences 
 of |'my_age'| are simply replaced with 32 by the preprocessor 
 http://tigcc.ticalc.org/doc/cpp.html, and no memory will be 
 allocated for it.

You perhaps refer to const modifier, which is different from declaring 
a constant, like in
 public:
 WinEDA_VertexCtrl( wxWindow* parent, const wxString title,
wxBoxSizer* BoxSizer, int units, int 
 internal_unit );

 Also, it would be correct to use static with const, the line below would
 be correct use.

 static const int daysPerMonth[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

In this case - talking about C and not C++:
 |static| tells that a function or data element is only known within 
 the scope of the current compile. In addition, if you use the |static| 
 keyword with a variable that is local to a function, it allows the 
 last value of the variable to be preserved between successive calls to 
 that function. 
const says that data is not modifiable, so static would say the same 
thing. Note also the ambiguity of the keyword when applied to data 
global to a module, and data local to a function - the same keyword does 
two very different things.


 Having said that, The original question was not about C,  I think Fabian
 was simply asking about the scope of constants in classes (in Gambas)

Uhm... is it forbidden to cite other languages to better explain a 
concept? So why you cited C++?

Anyway, you are right, the original question was about scope. In gambas 
scope is governed by PRIVATE and PUBLIC. Full stop.

If you feel that my reply is a little hurting, excuse me; it is because 
your reply seemed hurting to me. Prove to me that I am wrong and I will 
publicly apologize.

Regards,
Doriano

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Showing the Form's Gui

2010-04-14 Thread Jorge Carrión
Caveat:
Thank you very much for you module. I'll read it carefully.
Regards

2010/4/14 Caveat gam...@caveat.demon.co.uk

 Hi Jorge,

 While we wait to see if Ricardo wants to share his open forms method
 (I'm also interested to see it), here's some code I have used before
 (see attachment) where the opening/closing of forms is handled by a
 module, which I've called RunController.

 The module is set as the Startup Class (normally that's by default the
 first Form you declare I think) and must have a Main() method.
 Right-clicking on the module brings up a context menu where you can
 click on the Startup Class checkbox.

 You can see that the RunController module can decide when it opens each
 form (so you could have some long-running data extraction go on in the
 background), and handles events raised by the forms (in conjunction with
 Attach, making sure RunController actually gets the events).

 One of the first things RunController does is to decide should I first
 open up the settings form (no Dragons defined yet)? or should I show
 the main form already (at least one Dragon exists in settings)?:

  IF theSettings.getDragonCount() = 0 THEN
settingsFrm = NEW SettingsForm
settingsFrm.Show
Object.Attach(settingsFrm, ME, SettingsFrm)
  ELSE
Logger.logMessage(RunController.Main() dragon found, so starting
 Remote Control, FALSE)
remC = NEW RemoteControl
remC.Show
Object.Attach(remC, ME, Remote)
tCop = NEW TrafficCop
tCop.show
Object.Attach(tCop, ME, Cop)
  END IF

 One limitation of my approach is that you need to explicitly declare
 each form you're going to use up-front, so I'm interested to see if
 Ricardo's approach avoids that.

 Regards,
 Caveat



 On Wed, 2010-04-14 at 11:59 +0200, Jorge Carrión wrote:
  Ricardo:
  Could you post a example of your open forms method? I'm very interested
 on
  it. It sound like something I have searching for a long time.
 
  Gracias
 
  Jorge
 
 
  2010/4/13 Ricardo Díaz Martín oceanosoftlapa...@gmail.com
 
   If It can help to someone, this is I always do:
  
   When I'm going to open a form, I always call my own OpenForm(FormName
 as
   String, Parameters as String) sub. This sub is not inside the form I'm
   going
   to open. It's a public sub that's is inside a utilities module.
  
   OpenForm() sub create new object with the form (f.e. FRMMain) and put
 its
   reference inside a public collection called OpenedForms. Before to show
   form
   to the user, I show other form with a progress bar and a label showing
   Loading... and I'm going executing SQL, show/hid controls, etc...
 with no
   show anything. If there thrownare a fixed steps to data load, I updated
 progress
   bar and when load process finish I show the form.
  
   I use this in all my apps (since lot of years when I never eared about
   gambas and I was programing in VB, Access, Java, etc...) and for me is
 the
   best option. For sure there is a lot of ways to do this.
  
   Regards,
   Ricardo Díaz
  
  
  
   2010/4/13 Doriano Blengino doriano.bleng...@fastwebnet.it
  
Fabien Bodard ha scritto:
 2010/4/13 Doriano Blengino doriano.bleng...@fastwebnet.it:

 Fabien Bodard ha scritto:

 just remember to put a flag to say when the data are loaded !


 What would be the reason for this flag?

 if the form is showed and the data not accessible ?

Really, there could be a problem if the user clicks a button 50 ms
 after
the button (and the whole form) is visible. A remote possibility, and
application-dependent. But I know users enough to imagine that
 someone
could do it... :-)
   
Reducing the interval of the one-shot timer can help, but does not
 solve
(interval=0 could?). The better way is to disable actions the user
 could
do with invalid data (application dependent: who says that the form
 is
intended to receive clicks?), and perhaps add a nice label stating
Loading data, please wait... and so on.
   
Anyway, the flag is the worse solution. Supposing you use a flag, and
the user clicks or types too fast, what would you do? A
Message.Info(You clicked too fast. Go to have a coffee and come back
later.)? :-) Better to disable some controls, so the user is
 informed
before; in addition, controls are already global variables which
 carry
informations with them. Well, this is my opinion - I hate to
 duplicate
informations around, but someone else on this list, time ago, said
never use the GUI to store information. The problem with global (or
class) variables is that you can forget them more easily than some
property of a visible control.
   
Regards,
Doriano
   
   
   
   
  
 --
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel 

Re: [Gambas-user] static const?

2010-04-14 Thread Fabián Flores Vadell
2010/4/14 Doriano Blengino doriano.bleng...@fastwebnet.it:

 Back to the beginning: a CONST declaration is something that uses no
 memory, so it can not have instances, and hence it can not be STATIC.

 On the other hand, a CONST is always static, because the effective data
 it describes reside in a memory outside the program - they reside in the
 compiler memory.

Thanks Doriano. I understand that. My question was caused by the fact
that the compiler allows use the keyword STATIC in the declaration of
constants, even though the online help and a very basic logical
reasoning indicate that use the keyword STATIC is unnecesary in this
situation

 About the cycles WHILE, FOR, REPEAT and so on, I think the statements
 BREAK and CONTINUE are very useful (I would add a third statement:
 RESTART): they permit a finer control and many times they are clearer
 than complex tests.

You do not give arguments to support your opinion. Can you give me
some examples? I think, that these can be obvious for you, but not for
me.

 Your example only has two test, against COUNT and
 the CAPTION. What kind of test would you write if the conditions were
 15? Perhaps concatenated (I mean, some test are only meaningful when
 other conditions are met).

Assign the results of logical expressions to Boolean variables, it is
often the way to manage the complexity of conditionals expressions.
And in the loops, to use these variables instead of those logical
expressions.

But I think that you are knowing well this, and you points to the
performance of programs. If so, my answer is that the performance
isn't a priority in many types of programs, and the evaluation of
logical expressions have a little cost in comparation with other
operations (I/O, compression, among many others).

 Finally, your last lines of code do not work:

Yes, it works.

 PRIVATE FUNCTION ScanTab(IdCaption AS String) AS Byte
 DIM a AS Byte = 0

    WHILE (a  TabStrip1.Count - 1) AND (TabStrip1[a].Text  IdCaption)
      INC a
    WEND

    RETURN IF(TabStrip1[a].Caption = IdCaption, a, -1)
 END

 The third cycle does not get executed - a is 2, which is not less than
 3-1 (it is equal).

That's irrelevant because the external comprobation (the logical
expression in the return sentence)

 Moreover, your algorithm does a double test on caption, which could be
 avoided.

I think that the second test can't to be avoided. If it isn't put out
the loop, you have to put into the loop. The reason for include the
test (TabStrip1[a].Text  IdCaption) in conditional expression is
only stop the loop if there's match before get the last item.

I think that this code can to write in many ways, but with no
significant variations. How would you do?

 Doing an additional test is not an important thing if the test
 is quick and the routine is called not too much often. What if the
 routine is called millions time, or the test is more heavy?

I think that the computational cost of evaluate complex logical
expressions, generally is insignificant. But if not, then the first
thing to be considerated is the language to use, and I see few
alternatives: assembler, C, C++, someone else; the second thing is the
many optimizations to do. But, what kind the system would be? One that
is not possible to do with Gambas.

 About not using RETURN or BREAK inside cycles, we must think at
 different kind of cycles. The WHILE and alike, where no variables are
 directly involved in the cycle declaration, never have problems - the
 semantic of the declaration does not imply anything about variable
 allocation. In the FOR cycles instead, other languages can do strange
 things, both on allocation and code optimization, so it is effectively a
 bad idea to fiddle with the loop control variable; in other languages
 this is not stressed the same way (basic, for example), but actually is,
 at least, ugly.

Yep, but I not was thinking in possible collateral effects, derived
from implementation of language. (To those, the corresponding compiler
would let in evidence, or would become a logical error isn't very
difficult to detect and correct). I was thinking in conceptuals
implications.

This conceptuals implications derives in to use of the language
resources in any ways, instead to use them in the correct situations.

 It seems to me that you have said that an exception would be the FOR
 EACH cycle... why?

FOR EACH really iterates through all items, so there's only way to
stop the loop when it's goal is achieved, is by the BREAK sentence
used in a conditonal sentence inside the loop. But it might think that
if it is necessary to do this, then the iterative structure FOR EACH
is not adequate.

And I hope that my very ugly english, does not cause tears.

-- 
Fabián Flores Vadell
www.speedbooksargentina.blogspot.com

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, 

Re: [Gambas-user] static const?

2010-04-14 Thread Les Hardy

If you feel hurt I am sorry for that, it was not my intention to hurt 
you, and I have no wish to prove you wrong.
I do still stand by my statement.

Regards
Les Hardy



Doriano Blengino wrote:
 Les Hardy ha scritto:
   

 
 The C language, in facts, does not even have CONSTs - it goes with
 #define. So, it would be correct to forbid STATIC when declaring CONSTs.
  
   
 Surely this is not correct. ANSI C uses const, and C++ also uses the
 const keyword.
 #define (a preprocessor directive) is a relic from old C, and const is
 now recommended use instead.

 
 Surely, according to http://www.ericgiguere.com/articles/ansi-c-summary.html
   
 The declaration:
  enum colours { RED, BLUE, GREEN };


 would declare colours as an enumeration tag representing the integer 
 constants RED, BLUE and GREEN. These enumeration constants are given 
 integer values starting at 0 and increasing by 1 with each identifier.

 An enumeration constant may be used wherever an integer is expected. 
 The following is equivalent to the above enumerated type:

  #define RED   0
  #define BLUE  1
  #define GREEN 2

 

 Moreover, from http://tigcc.ticalc.org/doc/keywords.html
   
 _const_

 *Makes variable value or pointer parameter unmodifiable.*

 When |const| is used with a variable, it uses the following syntax:

 const/variable-name/  [ =/value/];


 In this case, the |const| modifier allows you to assign an initial 
 value to a variable that cannot later be changed by the program. For 
 example,

 const my_age = 32;


 Any assignments to |'my_age'| will result in a compiler error. 
 However, such declaration is quite different than using

 #define my_age 32

 In the first case, the compiler allocates a memory for |'my_age'| and 
 stores the initial value 32 there, but it will not allow any later 
 assignment to this variable. But, in the second case, all occurences 
 of |'my_age'| are simply replaced with 32 by the preprocessor 
 http://tigcc.ticalc.org/doc/cpp.html, and no memory will be 
 allocated for it.
 

 You perhaps refer to const modifier, which is different from declaring 
 a constant, like in
   
 public:
 WinEDA_VertexCtrl( wxWindow* parent, const wxString title,
wxBoxSizer* BoxSizer, int units, int 
 internal_unit );
 

   
 Also, it would be correct to use static with const, the line below would
 be correct use.

 static const int daysPerMonth[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

 
 In this case - talking about C and not C++:
   
 |static| tells that a function or data element is only known within 
 the scope of the current compile. In addition, if you use the |static| 
 keyword with a variable that is local to a function, it allows the 
 last value of the variable to be preserved between successive calls to 
 that function. 
 
 const says that data is not modifiable, so static would say the same 
 thing. Note also the ambiguity of the keyword when applied to data 
 global to a module, and data local to a function - the same keyword does 
 two very different things.

   
 Having said that, The original question was not about C,  I think Fabian
 was simply asking about the scope of constants in classes (in Gambas)

 
 Uhm... is it forbidden to cite other languages to better explain a 
 concept? So why you cited C++?

 Anyway, you are right, the original question was about scope. In gambas 
 scope is governed by PRIVATE and PUBLIC. Full stop.

 If you feel that my reply is a little hurting, excuse me; it is because 
 your reply seemed hurting to me. Prove to me that I am wrong and I will 
 publicly apologize.

 Regards,
 Doriano

   


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Showing the Form's Gui

2010-04-14 Thread Ricardo Díaz Martín
This is a gb2 project example about we were talking. Excuse me but is in
Spanish (I got no enough time to do something better than this). I was
cutting/pasting for a while and deleting extra thinks to get this example.
If not exactly the same I use but I hope It can help you.

Caveat, I need an explicit form declaration too because gambas can't create
a object by name (or I think so).

Please note it's only an example.

Regards,
Ricardo Díaz

El 14 de abril de 2010 18:48, Jorge Carrión sho...@gmail.com escribió:

 Caveat:
 Thank you very much for you module. I'll read it carefully.
 Regards

 2010/4/14 Caveat gam...@caveat.demon.co.uk

  Hi Jorge,
 
  While we wait to see if Ricardo wants to share his open forms method
  (I'm also interested to see it), here's some code I have used before
  (see attachment) where the opening/closing of forms is handled by a
  module, which I've called RunController.
 
  The module is set as the Startup Class (normally that's by default the
  first Form you declare I think) and must have a Main() method.
  Right-clicking on the module brings up a context menu where you can
  click on the Startup Class checkbox.
 
  You can see that the RunController module can decide when it opens each
  form (so you could have some long-running data extraction go on in the
  background), and handles events raised by the forms (in conjunction with
  Attach, making sure RunController actually gets the events).
 
  One of the first things RunController does is to decide should I first
  open up the settings form (no Dragons defined yet)? or should I show
  the main form already (at least one Dragon exists in settings)?:
 
   IF theSettings.getDragonCount() = 0 THEN
 settingsFrm = NEW SettingsForm
 settingsFrm.Show
 Object.Attach(settingsFrm, ME, SettingsFrm)
   ELSE
 Logger.logMessage(RunController.Main() dragon found, so starting
  Remote Control, FALSE)
 remC = NEW RemoteControl
 remC.Show
 Object.Attach(remC, ME, Remote)
 tCop = NEW TrafficCop
 tCop.show
 Object.Attach(tCop, ME, Cop)
   END IF
 
  One limitation of my approach is that you need to explicitly declare
  each form you're going to use up-front, so I'm interested to see if
  Ricardo's approach avoids that.
 
  Regards,
  Caveat
 
 
 
  On Wed, 2010-04-14 at 11:59 +0200, Jorge Carrión wrote:
   Ricardo:
   Could you post a example of your open forms method? I'm very interested
  on
   it. It sound like something I have searching for a long time.
  
   Gracias
  
   Jorge
  
  
   2010/4/13 Ricardo Díaz Martín oceanosoftlapa...@gmail.com
  
If It can help to someone, this is I always do:
   
When I'm going to open a form, I always call my own OpenForm(FormName
  as
String, Parameters as String) sub. This sub is not inside the form
 I'm
going
to open. It's a public sub that's is inside a utilities module.
   
OpenForm() sub create new object with the form (f.e. FRMMain) and put
  its
reference inside a public collection called OpenedForms. Before to
 show
form
to the user, I show other form with a progress bar and a label
 showing
Loading... and I'm going executing SQL, show/hid controls, etc...
  with no
show anything. If there thrownare a fixed steps to data load, I
 updated
  progress
bar and when load process finish I show the form.
   
I use this in all my apps (since lot of years when I never eared
 about
gambas and I was programing in VB, Access, Java, etc...) and for me
 is
  the
best option. For sure there is a lot of ways to do this.
   
Regards,
Ricardo Díaz
   
   
   
2010/4/13 Doriano Blengino doriano.bleng...@fastwebnet.it
   
 Fabien Bodard ha scritto:
  2010/4/13 Doriano Blengino doriano.bleng...@fastwebnet.it:
 
  Fabien Bodard ha scritto:
 
  just remember to put a flag to say when the data are loaded !
 
 
  What would be the reason for this flag?
 
  if the form is showed and the data not accessible ?
 
 Really, there could be a problem if the user clicks a button 50 ms
  after
 the button (and the whole form) is visible. A remote possibility,
 and
 application-dependent. But I know users enough to imagine that
  someone
 could do it... :-)

 Reducing the interval of the one-shot timer can help, but does not
  solve
 (interval=0 could?). The better way is to disable actions the user
  could
 do with invalid data (application dependent: who says that the form
  is
 intended to receive clicks?), and perhaps add a nice label stating
 Loading data, please wait... and so on.

 Anyway, the flag is the worse solution. Supposing you use a flag,
 and
 the user clicks or types too fast, what would you do? A
 Message.Info(You clicked too fast. Go to have a coffee and come
 back
 later.)? :-) Better to disable some controls, so the user is
  informed
 before; in addition, controls are already global 

Re: [Gambas-user] static const?

2010-04-14 Thread Doriano Blengino
Fabián Flores Vadell ha scritto:
 2010/4/14 Doriano Blenginodoriano.bleng...@fastwebnet.it:


 Back to the beginning: a CONST declaration is something that uses no
 memory, so it can not have instances, and hence it can not be STATIC.
  
 Thanks Doriano. I understand that. My question was caused by the fact
 that the compiler allows use the keyword STATIC in the declaration of
 constants, even though the online help and a very basic logical
 reasoning indicate that use the keyword STATIC is unnecesary in this
 situation

And here we return on your idea about a good compiler - and it is mine 
idea too. A good compiler should be very precise about things that have 
sense, and can be done, and things that can not be done, or have no meaning.
In this respect, it is a nonsense to let the user write a CONST 
STATIC. But compilers sometimes must keep compatibility with other, 
older, compilers. So, in this case, may be that VB(tm) was accepting 
this, and so does gambas. But I don't know VB(tm). Anyway, this issue is 
harmless, so I don't see it as a big problem.

 About the cycles WHILE, FOR, REPEAT and so on, I think the statements
 BREAK and CONTINUE are very useful (I would add a third statement:
 RESTART): they permit a finer control and many times they are clearer
 than complex tests.
  
 You do not give arguments to support your opinion. Can you give me
 some examples? I think, that these can be obvious for you, but not for
 me.

First of all, I must say that I see your point. May be that all the 
issue is about personal style. But I did a quick research in my sources 
to let you see some example. I have little code in gambas - I use a lot 
C, about which I could have many examples but, as stated by someone 
other, it is forbidden to talk about C...

First example. I store some bookmarks in a file by using the Settings 
class. Every bookmark is stored with a name like Bmark1, Bmark2 and 
so on, but I don't know how many of them are in the file. I know when 
there are no more values, instead. So the routine is the following:

   i = 1
   DO
 st = settings[Bmark  i, ]
 IF st =  THEN BREAK
 men = NEW Menu(mnBooks) AS chgBook
 men.Caption = st
 INC i
   LOOP

Now, to understand if there are more bookmarks to read, I must try to 
read it. If the value is NULL, then the job is finished. Clearly, a 
FOR-NEXT is no good (or, one can write a for-next from 1 to 1000... 
misleading...).
I could break out the loop using a logic variable, but this way I save a 
variable. Or I could test the variable in the loop construct, like this:

   i = 1
   DO
 st = settings[Bmark  i, ]
 if st then
   men = NEW Menu(mnBooks) AS chgBook
   men.Caption = st
 ENDIF
 INC i
   while st

but, as you see, there are TWO tests instead of one, and there is an 
added line of code. May be that I am missing something, but the BREAK 
instruction is really useful here.

The second example is a textual search on a treeview. If the user types 
some text, the selection is moved on the next item beginning with that 
text. If no more items satisfy the criterium, the search must start 
again at the top, but only once. So the code (there is a ME.MoveBelow() 
just before this code, I omitted it for simplicity):

   i = Len(searchstring)
   FOR tries = 1 TO 2' to search again from the top
 DO
   IF Upper(Left(ME.item.Text, i)) = searchstring THEN
 ' found item
 RETURN
   ENDIF
   IF ME.MoveBelow() THEN BREAK
 LOOP
 ME.MoveFirst
   NEXT

Here, the FOR-NEXT is a quick way to execute some code for no more than 
two times...
Again, I could have used a variable to store the result of the test, but 
I saved it...
And again this is not, perhaps, the best code you can see around - but 
it works, and it is reasonably fast and short.



 Your example only has two test, against COUNT and
 the CAPTION. What kind of test would you write if the conditions were
 15? Perhaps concatenated (I mean, some test are only meaningful when
 other conditions are met).
  
 Assign the results of logical expressions to Boolean variables, it is
 often the way to manage the complexity of conditionals expressions.
 And in the loops, to use these variables instead of those logical
 expressions.

 But I think that you are knowing well this, and you points to the
 performance of programs. If so, my answer is that the performance
 isn't a priority in many types of programs, and the evaluation of
 logical expressions have a little cost in comparation with other
 operations (I/O, compression, among many others).

I agree, and partly not.
I think that clearness and beatiful code is to prefer against speed, but 
only when speed is not an issue.
In the text-search example speed *is* an issue. Never tried to open a 
directory with some 3 files in it, and perform a textual search? KDE 
solves elegantly... it does textual search *only* if the sort order is 
by name. 

Re: [Gambas-user] Showing the Form's Gui

2010-04-14 Thread Fabien Bodard
i don't know if richard want the user to be able to do anything on the
showed form before the tatal loading ...


the better way will be to do the loading in the timer by use the
timer.trigger function

the form .enabled will be set to false

and the timer just set the form.enabled to true when the loading is ok

when you set a contained enabled to false all the form content is set
to false too. So the form is showed but not editable.



2010/4/13 Doriano Blengino doriano.bleng...@fastwebnet.it:
 Fabien Bodard ha scritto:
 2010/4/13 Doriano Blengino doriano.bleng...@fastwebnet.it:

 Fabien Bodard ha scritto:

 just remember to put a flag to say when the data are loaded !


 What would be the reason for this flag?

 if the form is showed and the data not accessible ?

 Really, there could be a problem if the user clicks a button 50 ms after
 the button (and the whole form) is visible. A remote possibility, and
 application-dependent. But I know users enough to imagine that someone
 could do it... :-)

 Reducing the interval of the one-shot timer can help, but does not solve
 (interval=0 could?). The better way is to disable actions the user could
 do with invalid data (application dependent: who says that the form is
 intended to receive clicks?), and perhaps add a nice label stating
 Loading data, please wait... and so on.

 Anyway, the flag is the worse solution. Supposing you use a flag, and
 the user clicks or types too fast, what would you do? A
 Message.Info(You clicked too fast. Go to have a coffee and come back
 later.)? :-) Better to disable some controls, so the user is informed
 before; in addition, controls are already global variables which carry
 informations with them. Well, this is my opinion - I hate to duplicate
 informations around, but someone else on this list, time ago, said
 never use the GUI to store information. The problem with global (or
 class) variables is that you can forget them more easily than some
 property of a visible control.

 Regards,
 Doriano


 --
 Download Intel#174; Parallel Studio Eval
 Try the new software tools for yourself. Speed compiling, find bugs
 proactively, and fine-tune applications for parallel performance.
 See why Intel Parallel Studio got high marks during beta.
 http://p.sf.net/sfu/intel-sw-dev
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-14 Thread Doriano Blengino
Errata corrige:

 
 Finally, your last lines of code do not work:
  
   
 Yes, it works.


 
 PRIVATE FUNCTION ScanTab(IdCaption AS String) AS Byte
 DIM a AS Byte = 0

 WHILE (aTabStrip1.Count - 1) AND (TabStrip1[a].Text
 IdCaption)
   INC a
 WEND

 RETURN IF(TabStrip1[a].Caption = IdCaption, a, -1)
 END

 

 
 The third cycle does not get executed - a is 2, which is not less than
 3-1 (it is equal).
  
   
 That's irrelevant because the external comprobation (the logical
 expression in the return sentence)

 
 May be that I am missing something, but... how can you say that it works 
 if it omits to test the last item?
   
Time later, driving to home and still thinking about this routine, I 
finally recalled what you wanted to say with comprobation.
Yes, you are right - your code works. If I would have payed more 
attention to the routine, I would have noticed. But, stupidly, I 
concentrated only on the cycle, noting that it was missing a test on the 
last item. That last item is managed by the last test before exiting.

Still I don't like this routine. What happens if TabStrip1.Count=0 
(emtpy tabstrip)?

Ok, now I'am home, it's late - so good night to everybody (in Europe, of 
course).

Regards,

-- 
Doriano Blengino

Listen twice before you speak.
This is why we have two ears, but only one mouth.


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] There are errors in the class Key , and in the events KeyPress / KeyRelease?

2010-04-14 Thread Benoît Minisini
  Key.Text is not guaranteed to be set during a KeyRelease.
 
 (Do you means readed? Ok, you are look at from compiler dev perspective.
 Right?)
 
 Why it's in that way?
 

Because Qt loses some information needed by the KeyRelease event when some 
compound keys are used.

-- 
Benoît Minisini

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-14 Thread Fabián Flores Vadell
2010/4/14 Doriano Blengino doriano.bleng...@fastwebnet.it:
 And here we return on your idea about a good compiler - and it is mine
 idea too.

I don't want judge if the Gambas compiler is good or not, I feel that
I don't have the knowledge or experience required for do that. But, I
shared with you about the taste for a compiler that to say at
programmer: This is right. That's not a good idea.

 First of all, I must say that I see your point. May be that all the
 issue is about personal style.
Yes, I have to admit that the style surely have influence in the
beauty criteria.

 But I did a quick research in my sources
 to let you see some example. I have little code in gambas - I use a lot
 C, about which I could have many examples but, as stated by someone
 other, it is forbidden to talk about C...

Ha! Is forbidden if you want that I can understand you. That is true :)

 First example. I store some bookmarks in a file by using the Settings
 class. Every bookmark is stored with a name like Bmark1, Bmark2 and
 so on, but I don't know how many of them are in the file. I know when
 there are no more values, instead. So the routine is the following:

   i = 1
   DO
     st = settings[Bmark  i, ]
     IF st =  THEN BREAK
     men = NEW Menu(mnBooks) AS chgBook
     men.Caption = st
     INC i
   LOOP
 ...

 I could break out the loop using a logic variable, but this way I save a
 variable. Or I could test the variable in the loop construct, like this:

 ...


 but, as you see, there are TWO tests instead of one, and there is an
 added line of code.

I don't agree the criteria for saving one variable or one expresion if
it is not justified.

 May be that I am missing something, but the BREAK
 instruction is really useful here.

I don't say that BREAK (and other sentences) haven't utility, but that
isn't strictly necessary (perhaps I said unnecesary and this word may
be incorrect).

 The second example is a textual search on a treeview. If the user types
 some text, the selection is moved on the next item beginning with that
 text. If no more items satisfy the criterium, the search must start
 again at the top, but only once. So the code (there is a ME.MoveBelow()
 just before this code, I omitted it for simplicity):

   i = Len(searchstring)
   FOR tries = 1 TO 2    ' to search again from the top
     DO
       IF Upper(Left(ME.item.Text, i)) = searchstring THEN
         ' found item
         RETURN
       ENDIF
       IF ME.MoveBelow() THEN BREAK
     LOOP
     ME.MoveFirst
   NEXT

 Here, the FOR-NEXT is a quick way to execute some code for no more than
 two times...
 Again, I could have used a variable to store the result of the test, but
 I saved it...

I think that you use a structure FOR-NEXT that requires to you knowing
the amount of iterations to do. But, in this case you know that is
likely the number of iterations declared could be unnecesary. So,
conceptually, the correct loop would be one that allow control the
number of iterations.

There isn't a practical problem here. Just a conceptual consideration.
This doesn't matter if you understand what you do, like in you case.
But I think that's important for who is learning to programming. (I'm
sorry, I'm a teacher -and may be some day I have to teach
programming-). However, I don't want keep with older patterns of
thought. So, will I keep open my mind.

Now, image an hypothetical case in that you have to do several
conditional actions inside the loop. If you resolves it in that way,
the code become hard to understand.

Catch the joke:

  FOR tries = 1 TO 2' to search again from the top
DO
  IF Upper(Left(ME.item.Text, i)) = searchstring THEN
' found item
RETURN
  ENDIF
  IF ME.MoveBelow() THEN BREAK
  IF (YOU DONT LIKE) THEN RETURN
  IF (YOU WANT) THEN RETURN
  IF (NOT ME ..). THEN BREAK
  IF (YOU DONT...) THEN BREAK
  IF (YOU WRITE IN C) THEN RETURN
  ...
LOOP
ME.MoveFirst
  NEXT

Ok, I know you wouldn't write something like that. Just I want to
serve to show what I mean.

 I think that clearness and beatiful code is to prefer against speed, but
 only when speed is not an issue.

I agree.

 In the text-search example speed *is* an issue. Never tried to open a
 directory with some 3 files in it, and perform a textual search?

Ok, I agree.

 I would do so:

 PRIVATE FUNCTION ScanTab(IdCaption AS String) AS Byte
 DIM a AS Byte = 0

   WHILE a  TabStrip1.Count
      if TabStrip1[a].Text = IdCaption then return a
     INC a
   WEND
   return -1
 END

 PRIVATE FUNCTION ScanTab(IdCaption AS String) AS Byte
 DIM a AS Byte

   for a = 0 to TabStrip1.Count-1
      if TabStrip1[a].Text = IdCaption then return a
   next
   return -1
 END

If you have to do tests (like unit tests) and you have routines with
multiple exit points, maybe you will have some coverage problems. What
do you think?

 No, the issue is different. Giving any language and any cpu, every
 operation has a cost. Comparing two 

Re: [Gambas-user] static const?

2010-04-14 Thread Fabián Flores Vadell
2010/4/14 Doriano Blengino doriano.bleng...@fastwebnet.it:
 Errata corrige:

 May be that I am missing something, but... how can you say that it works
 if it omits to test the last item?


 Time later, driving to home and still thinking about this routine, I
 finally recalled what you wanted to say with comprobation.
 Yes, you are right - your code works. If I would have payed more
 attention to the routine, I would have noticed. But, stupidly, I
 concentrated only on the cycle, noting that it was missing a test on the
 last item. That last item is managed by the last test before exiting.

 Still I don't like this routine. What happens if TabStrip1.Count=0
 (emtpy tabstrip)?

Ouch! TabStrip without tabs doesn't fit in my mind, ie Why somebody
want a TabStrip without at least one tab?

Moreover, by default TabStrip have one tab. (design time and execution time).

 Listen twice before you speak.
 This is why we have two ears, but only one mouth.

ha! Very funny. I like it.

Regards.

-- 
Fabián Flores Vadell
www.speedbooksargentina.blogspot.com

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] There are errors in the class Key, and in the events KeyPress / KeyRelease?

2010-04-14 Thread Fabián Flores Vadell
2010/4/14 Benoît Minisini gam...@users.sourceforge.net:
  Key.Text is not guaranteed to be set during a KeyRelease.

But, refering to the values provided by the key class, is guaranted
their availability within the routines that are called from KeyPress?

 Why it's in that way?

 Because Qt loses some information needed by the KeyRelease event when some
 compound keys are used.

Ok. Thanks.

-- 
Fabián Flores Vadell
www.speedbooksargentina.blogspot.com

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user