News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Object Oriented Code Attempt

Started by DarkWolf, April 12, 2007, 12:41:48 AM

Previous topic - Next topic

DarkWolf

Can I set a boolean variable in a header ?

boolean := false;

this returns an error that it expected ; where it found :=
I wanted to use a boolean variable as a flag and clear it by default.

What is the variable for the file.create() method ?
The HLAref says that I can use filevar.create() where filevar is the variable
But if the variable is in a class do I need to use this.filevar in the place of filevar ?

I'm getting there, I'll just be screwing up the little things for awhile :-)
--
Where's there's smoke, There are mirrors.
Give me Free as in Freedom not Speech or Beer.
Thank You and Welcome to the Internet.

Evenbit

Quote from: DarkWolf on July 01, 2007, 01:17:43 AM
Can I set a boolean variable in a header ?

boolean := false;

this returns an error that it expected ; where it found :=
I wanted to use a boolean variable as a flag and clear it by default.

You will want...
flag01    :boolean    :=    false;

Quote
What is the variable for the file.create() method ?
The HLAref says that I can use filevar.create() where filevar is the variable
But if the variable is in a class do I need to use this.filevar in the place of filevar ?

I'm getting there, I'll just be screwing up the little things for awhile :-)

Something like...
MyFile    :file;
or..
MyFile    :pointer to file

Nathan.

DarkWolf

Well I use a different name for my flag but that is exactly what I have in the header and it doesn't work.
I don't see what difference there is between :
isUnit: boolean := false;
and
flag01    :boolean    :=    false;
Apart from whitespace, but I never had a problem with that before.

Argh, it was one page above what I was reading. (slaps hand on forehead, I need a SHOF icon :-p )
But now I am thinking (and maybe a little too hard), I will need to use the file.class methods in another class.
TO have my method write to a file I need it to call the methods of the file.class from the standard library.

Am I thinking too hard or is there an issue if I call say MyFile.put("whatever") from inside a method from another class.
--
Where's there's smoke, There are mirrors.
Give me Free as in Freedom not Speech or Beer.
Thank You and Welcome to the Internet.

Randall Hyde

As long as your declaration appears in a CONST, STATIC, or READONLY section, it should be fine.  I.e.,


static
    isUnit :boolean := false;


HOWEVER, keep in mind that if you do this, you will create a *distinct* copy of this variable in every file in which you include that header. And if you also make the symbol @external, you will get a linker error.

I suspect that from the name of the variable you're wanting to create a constant that you can check with conditional assembly, e.g.,


const
   isUnit :boolean := false;


But if you really want to include the variable in multiple files (as part of the header file), then the typical way to do this is


// in your header file:

static // or readonly

  isUnit:boolean; @external;


and then in *only one* of your .hla files (that includes the header files), you'll want the following:


static // or readonly
  isUnit :boolean := false;

hLater,
Randy Hyde



DarkWolf

No, I don't intend it to be constant. Only false by default, I'll set it to true if I need to.
But I see that I am using the wrong section.

Conditional compiling was not what I originally intended, at first I wanted to use them to determine the file I was writing.
For instance, if isUnit was true it would write a file without the program ID statement.
--
Where's there's smoke, There are mirrors.
Give me Free as in Freedom not Speech or Beer.
Thank You and Welcome to the Internet.

Randall Hyde

Quote from: DarkWolf on July 04, 2007, 11:13:15 PM
No, I don't intend it to be constant. Only false by default, I'll set it to true if I need to.

In that case, use the @external directive, and in the *one* source file where you actually define the variable (rather than just use it), set it to false (in the STATIC section).
hLater,
Randy Hyde

DarkWolf

So far this is what I got and I know it is probably poorly written  :-p

I know that I need to clean it up. I didn't want it to ask for each string variable from the user but I started writing it that way.
And I am not sure about writing the file based on the boolean values.
(Don't bother with the exe in the zip I know it's bad.)

I didn't get to do much with it this week (10 hour shifts at work and Neverwinter Nights :-p )

[attachment deleted by admin]
--
Where's there's smoke, There are mirrors.
Give me Free as in Freedom not Speech or Beer.
Thank You and Welcome to the Internet.