Oxygen Basic

Information => Open Forum => Topic started by: kryton9 on July 03, 2011, 01:53:35 AM

Title: Can't get my console class to work
Post by: kryton9 on July 03, 2011, 01:53:35 AM
Having some problems still, but it is getting there:
Problems noted in source code files:
TestConsoleC01.o2bas and TestConsoleC02.o2bas

Attached is a 7zip file projects.7z: projects/kent/ 8 files

8 files:
BaseUtils.inc
ConsoleC.inc
TestConsoleC01.o2bas through TestConsoleC06.o2bas

thanks in advance!

[attachment deleted by admin]
Title: Re: Can't get my console class to work
Post by: kryton9 on July 03, 2011, 03:18:36 AM
I got it figured out, but not the way it should be.

I had to manually call the constructor and to be safe I called the destructor.
Here is the working code.
Code: OxygenBasic
  1. include once "ConsoleC.inc"
  2. include once "BaseUtils.inc"
  3.  
  4. int i
  5. string s$
  6.  
  7.  
  8. ConsoleC c
  9. c.Constructor( "kent console test" )
  10.     For i = 1 to 5
  11.         c.Print "This is string "  str(i) crlf$
  12.     Next i
  13.  
  14.     c.Print "press any key"  crlf$
  15.     c.GetKey
  16.  
  17.     s$ = c.Input "enter data -> "
  18.     c.Print "Data = "  s$ crlf$
  19.  
  20.     c.Print "press any key"  crlf$
  21.     c.GetKey
  22. c.Destructor()

This is the way it should be, in my opinion. Where the constructor and destructor are called automatically.
Code: OxygenBasic
  1. include once "ConsoleC.inc"
  2. include once "BaseUtils.inc"
  3.  
  4. int i
  5. string s$
  6.  
  7.  
  8. ConsoleC c( "kent console test" )
  9.  
  10. For i = 1 to 5
  11.     c.Print "This is string "  str(i) crlf$
  12. Next i
  13.  
  14. c.Print "press any key"  crlf$
  15. c.GetKey
  16.  
  17. s$ = c.Input "enter data -> "
  18. c.Print "Data = "  s$ crlf$
  19.  
  20. c.Print "press any key"  crlf$
  21. c.GetKey
  22.  
Title: Re: Can't get my console class to work
Post by: kryton9 on July 03, 2011, 03:50:57 AM
This does work as I thought it should, but it is using dynamic memory where as the previous should be just using program memory and work.
Code: OxygenBasic
  1. include once "ConsoleC.inc"
  2. include once "BaseUtils.inc"
  3.  
  4. int i
  5. string s$
  6.  
  7.  
  8. new ConsoleC c "kent test console"  'using new so make sure to delete when finished
  9.  
  10. For i = 1 to 5
  11.     c.Print "This is string "  str(i) crlf$
  12. Next i
  13.  
  14. c.Print "press any key"  crlf$
  15. c.GetKey
  16.  
  17. s$ = c.Input "enter data -> "
  18. c.Print "Data = "  s$ crlf$
  19.  
  20. c.Print "press any key"  crlf$
  21. c.GetKey
  22. del c 'deleting
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 03, 2011, 01:13:09 PM

Hi Kent,

Today the compiler is dismantled and I have the engine blocks out :)
I think there's another 16 hours of work to go before it is up and running again and I can disengage from the task. Doing some major mods for auto string/number conversions.

Will look at your code as soon as I can.

Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on July 03, 2011, 01:24:40 PM
Good luck Charles with your core work. No need to rush on my code, I got it figured out. We can talk about the auto constructor call in non dynamic creations of an object later.
Title: Re: Can't get my console class to work
Post by: kryton9 on July 03, 2011, 11:06:55 PM
Here is a screenshot of the console class in action so far. Got some more things to add to it.
Here is the code for that output:
Code: OxygenBasic
  1. 'Last modified:
  2. '2011.07.04 02:50 KS
  3.  
  4. include once "ConsoleC.inc"
  5.  
  6. sys i
  7. string s$
  8.  
  9. new ConsoleC c "Window Console Title: TestConsoleC.o2bas"
  10.  
  11.     c.SetColor FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY
  12.     s$ = c.GetTitle() crlf$
  13.     c.Print s$ crlf$ crlf$
  14.    
  15.     c.SetColor FOREGROUND_RED or FOREGROUND_BLUE or FOREGROUND_INTENSITY
  16.     s$ = c.Input "Enter data: "
  17.     c.SetColor DEFAULT_COLOR
  18.     c.Print crlf$ "Data entered: " s$ crlf$  crlf$
  19.  
  20.     c.SetColor  F_DARK_GREEN   : c.Print "DARK_GREEN"    crlf$
  21.     c.SetColor  F_GREEN        : c.Print "GREEN"         crlf$        
  22.     c.SetColor  F_DARK_BLUE    : c.Print "DARK_BLUE"     crlf$    
  23.     c.SetColor  F_BLUE         : c.Print "BLUE"          crlf$        
  24.     c.SetColor  F_DARK_RED     : c.Print "DARK_RED"      crlf$    
  25.     c.SetColor  F_RED          : c.Print "RED"           crlf$          
  26.     c.SetColor  F_DARK_YELLOW  : c.Print "DARK_YELLOW"   crlf$  
  27.     c.SetColor  F_YELLOW       : c.Print "YELLOW"        crlf$      
  28.     c.SetColor  F_DARK_PURPLE  : c.Print "DARK_PURPLE"   crlf$
  29.     c.SetColor  F_PURPLE       : c.Print "PURPLE"        crlf$      
  30.     c.SetColor  F_DARK_CYAN    : c.Print "DARK_CYAN"     crlf$    
  31.     c.SetColor  F_CYAN         : c.Print "CYAN"          crlf$
  32.     c.SetColor  F_DARK_GREY    : c.Print "DARK_GREY"     crlf$    
  33.     c.SetColor  F_GREY         : c.Print "GREY"          crlf$        
  34.     c.SetColor  F_WHITE        : c.Print "WHITE"         crlf$
  35.    
  36.     c.SetCPos 20, 30
  37.     'only B_DARK_GREEN will print at the cursor position
  38.    c.SetColor  B_DARK_GREEN   : c.Print "DARK_GREEN "   crlf$
  39.     c.SetColor  B_GREEN        : c.Print "GREEN      "   crlf$        
  40.     c.SetColor  B_DARK_BLUE    : c.Print "DARK_BLUE  "   crlf$    
  41.     c.SetColor  B_BLUE         : c.Print "BLUE       "   crlf$        
  42.     c.SetColor  B_DARK_RED     : c.Print "DARK_RED   "   crlf$    
  43.     c.SetColor  B_RED          : c.Print "RED        "   crlf$          
  44.     c.SetColor  B_DARK_YELLOW  : c.Print "DARK_YELLOW"   crlf$  
  45.     c.SetColor  B_YELLOW       : c.Print "YELLOW     "   crlf$      
  46.     c.SetColor  B_DARK_PURPLE  : c.Print "DARK_PURPLE"   crlf$
  47.     c.SetColor  B_PURPLE       : c.Print "PURPLE     "   crlf$      
  48.     c.SetColor  B_DARK_CYAN    : c.Print "DARK_CYAN  "   crlf$    
  49.     c.SetColor  B_CYAN         : c.Print "CYAN       "   crlf$
  50.     c.SetColor  B_DARK_GREY    : c.Print "DARK_GREY  "   crlf$    
  51.     c.SetColor  B_GREY         : c.Print "GREY       "   crlf$        
  52.     c.SetColor  B_WHITE        : c.Print "WHITE      "   crlf$
  53.    
  54.     c.SetColor DEFAULT_COLOR
  55.     c.Print crlf$ crlf$ crlf$
  56.     c.Print "Press a key to exit." crlf$
  57.     c.GetKey
  58. del c

[attachment deleted by admin]
Title: Re: Can't get my console class to work
Post by: kryton9 on July 04, 2011, 02:15:39 AM
I updated the first post Charles with my latest files. I am having problems with a function. I tried everything I could think of with pointer syntax to get it working and none of them worked for me.

Three areas to look.
ConsoleC.inc: sys GetConsoleScreenBufferInfo( sys hConsoleOutput, CONSOLE_SCREEN_BUFFER_INFO *lpConsoleScreenBufferInfo )
ConsoleC.inc: method GetSBI( CONSOLE_SCREEN_BUFFER_INFO aSBI ) as sys
TestConsoleC02.o2bas:CONSOLE_SCREEN_BUFFER_INFO aSBI and if c.GetSBI aSBI then

Hope your engine overall is going well!

Attachments in first post, thanks.
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 04, 2011, 11:09:07 PM

Hi Kent,

A quick note about constructors and destructors:

Only dynamically defined objects automatically call constructor/destructor methods. The keywords new and del are actually macros:

Code: [Select]

def new %1 * %2 : @%2=?news sizeof %1 : %2.constructor

def  del %1.destructor : frees @%1 : @%1=0


Oxygen classes are naturally lazy. All objects, like basic variables are initialised to the null state but constructor and destructor methods are not assumed. This is advantageous for minor classes. I wanted to make classes as near to user-defined-types as possible.

Programmers are free to make their own macros for creating and initialising objects.

Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on July 05, 2011, 01:47:31 AM
That's fine Charles. I just need to add that to the reference.

I still couldn't get that method above I wrote about to work.
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 05, 2011, 03:56:53 PM

Kent,

I am still working on Oxygen core. This will have a more sophisticated autotype conversion. I persist on the grounds that what doesn't kill you makes you stronger! :)

I nearly have it working then I can release my focus.

Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on July 05, 2011, 04:53:44 PM
Good luck Charles. I am sure it is a very tough job, glad you are getting stronger :)
Title: Re: Can't get my console class to work
Post by: Peter on July 06, 2011, 03:25:15 AM
And the simpleness stays on the route.  :D
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 06, 2011, 03:36:48 AM

Simpler I anticipate.

str() and val() are almost redundant.

Instead of performing numerology this will produce a proper total:

print "sum " 1 2 3 4 5 6 7

Most of the effort goes into ensuring it works with all variables, procedures and objects.

Charles

Title: Re: Can't get my console class to work
Post by: Peter on July 06, 2011, 04:43:29 AM
Str(), Val()  and something else,  that was my apprehension !    :-[
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 06, 2011, 05:06:53 AM

These functions will still be present. The changes make the compiler handle different types more intelligently. The main impact is on light-duty programming. It narrows the gap between compiling and scripting Basic.

Charles
Title: Re: Can't get my console class to work
Post by: JRS on July 06, 2011, 01:51:03 PM
Quote
It narrows the gap between compiling and scripting Basic.

I'm glad one of the Basic compiler authors get it. I'm spoiled using SB and would have a hard time going back to defining and declaring everything before use.

Nice job Charles and looking forward to OxygenBasic maturing as time goes on.

Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 06, 2011, 10:06:04 PM
Hi Kent,

Got your console working!

There wasn't much wrong with it :)

missing * for passing byref

the RetValue was not assigned to - I've done it direct.

The other corrections were to remove the str from c.print procedures

You don't need $ or % suffixes. I try to ensure these are stripped from all symbols  internally.

Code: OxygenBasic
  1.  
  2.         method GetSBI( CONSOLE_SCREEN_BUFFER_INFO *aSBI ) as sys
  3.             return GetConsoleScreenBufferInfo GetOutputHandle, aSBI
  4.         end method
  5.  
  6.  

I have included your code in the Oxygen projects folder

Charles
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 06, 2011, 10:42:36 PM

Hi John,

A selection of Hello Worlds in different programming languages. Some have noisier syntax than others.

Charles

Code: [Select]

LISP

"Hello!"

BASIC

print "Hello"


COBOL

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.     HELLOWORLD.
000300
000400*
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 SOURCE-COMPUTER. RM-COBOL.
000800 OBJECT-COMPUTER. RM-COBOL.
000900
001000 DATA DIVISION.
001100 FILE SECTION.
001200
100000 PROCEDURE DIVISION.
100100
100200 MAIN-LOGIC SECTION.
100300 BEGIN.
100400     DISPLAY " " LINE 1 POSITION 1 ERASE EOS.
100500     DISPLAY "Hello world!" LINE 15 POSITION 10.
100600     STOP RUN.
100700 MAIN-LOGIC-EXIT.
100800     EXIT.


FORTRAN

       program hello
          print *, "Hello World!"
       end program hello
 
PASCAL

program Hello;
 
begin
   Write('Hello world');
end.



C++

#include <iostream>
using namespace std;
void main()
{
  cout << "Hello World!" << endl;   cout << "Welcome to C++ Programming" << endl; }

JAVA

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}

JAVASCRIPT

<script type="text/javascript">
document.write('<b>Hello World</b>');
</script>

Title: Re: Can't get my console class to work
Post by: JRS on July 07, 2011, 12:00:50 AM
My comfort zone has been with ScriptBasic on the server, JavaScript on the client and jQuery for sex appeal. Runs on all the popular platforms (32/64 bit) and compatible with a broad range of browsers. Mobile computing is driving desktop applications to the web. IMHO
Title: Re: Can't get my console class to work
Post by: kryton9 on July 07, 2011, 01:48:31 PM
I had tried that Charles, strange it worked for you and not for me. I will download your version to see. Thanks.
Title: Re: Can't get my console class to work
Post by: Peter on July 07, 2011, 02:24:22 PM
If I see this psycho scrawniness then I am feeling so bad.
Programmers live in another world without reference to the reality.
What they need is a spelling police.  :D
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 07, 2011, 04:21:43 PM

Bug Alert!

If you downloaded the Oxygen in-progress version within the last 24 hours.
I found a few of my examples not working - due to some of the expressions using floats being mis-compiled. I have just fixed this and reposted.

The moral is: don't assume you understand your own code. The Charles of six months ago was a different programmer!

We are almost ready for release Alpha 036.

Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on July 07, 2011, 07:38:02 PM
I really the progress so far Charles. Getting rid of ( ) requirement in so many places really helps the code look nice.

I am finding that putting an m prefix in front of member variables really helps. An a prefix in front of arguements being passed to methods of a class. Using Capital First letters for all Methods and Capitals for all subs and functions, then first letter lowercase for normal variables with camel case really helps solve the problem with naming conflicts. Dummy example code below:
class DummyC
private 'vars
    string mName
    string mOccupation
public 'methods
    method SetData( string aName, aOccupation)
        mName = aName
        mOccupation = aOccupation
    end method
end class

new DummyC d
      sys numDoctors = 11
      d.SetData "Dr Who", "Time Lord"
del d

Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 08, 2011, 12:48:45 AM

This might be of use, Kent.

with this.   .. end with

especially in methods with named params where you want to keep the names simple for the user.

Code: OxygenBasic
  1.   class thing
  2.   '==========
  3.  
  4.   double length,width,depth, u
  5.  
  6.   method SetSize( double length=1, width=1,depth=1, string unit="cm" )
  7.   u=1
  8.   if unit="cm" then
  9.     u=1
  10.   elseif unit="m"
  11.     u=100
  12.   elseif unit="in"
  13.     u=2.54
  14.   end if
  15.   '
  16.  with this.
  17.   length=length*u
  18.   width=width*u
  19.   depth=depth*u
  20.   end with
  21.   '
  22.  end method
  23.  
  24.  
  25.  
  26.  
  27.   end class
  28.  
  29.   'TEST:
  30.  '=====
  31.  
  32.   thing t
  33.   t.SetSize  length=2, unit="in"
  34.  
  35.   print "check length stored: "  t.length
  36.  

Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on July 08, 2011, 02:09:05 AM
Nice options, but it might be good for the user, but can get confusing to me. Look at how much trouble I am having with this simple method, yikes.
  
I added to the console class, but it is not working again. I have a few more things I want to add that will make it really cool. But I need to get this working. I am instead of just writing a simple console wrapper wanting to make it easier to use with less code.

Here is the code so far attached. Hopefully you can see why it compiles fine, but goes into lala land when run.

outdated attachments removed to avoid confustion.
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 08, 2011, 04:04:25 AM
Yes Kent,

yes we have a mapping problem with UDTs, particularly when they do not align to 4 bytes. This will be my bug fix of the day!

But you only need to add one word in your case , and everything works.

dim ...

The makes mSBI a static variable of the class. But not part of the class table.

Code: OxygenBasic
  1.         dim CONSOLE_SCREEN_BUFFER_INFO mSBI
  2.  

Charles
Title: Re: Can't get my console class to work
Post by: Peter on July 08, 2011, 04:51:06 AM
Code: [Select]
The Charles of six months ago was a different programmer!
Brainwash ?

Title: Re: Can't get my console class to work
Post by: efgee on July 08, 2011, 10:39:46 AM
...yes we have a mapping problem with UDTs, particularly when they do not align to 4 bytes. This will be my bug fix of the day!

That's why I stopped working on my console or windows classes; too many bugs waste too much of my time.

Suppose that's why it's still called: alpha. ;D

When the next version will be out I will give oxygen another shot.

Take care
efgee
Title: Re: Can't get my console class to work
Post by: efgee on July 08, 2011, 11:13:50 AM
Quote
It narrows the gap between compiling and scripting Basic.

I'm glad one of the Basic compiler authors get it. I'm spoiled using SB and would have a hard time going back to defining and declaring everything before use.

To explicitly declare stuff and write comments next to it to describe for what's used is paramount:
1.) In an environment where collaboration between programmers is needed
2.) If the code needs to be readable after several years even by only one programmer.

Hope oxygen will have/keep the EXPLICIT option :)


Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 08, 2011, 01:24:43 PM

Hi Efgee,

Although Oxygen is small, there are are large number of permutations to test, especially on the OOP side. If you use frequent develop/test cycles and work in small increments, bug detection is much easier.

There are 2 commands for firming up code discipline:

#autodim and #unique

thus:

def strict #autodim off

def stricter #autodim off : #unique on

or even:

def whiplash #autodim off : #unique on : #case sensitive   ;D

Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on July 08, 2011, 08:44:47 PM
Thanks Charles for the help. Again one of those bugs I would never have guessed how to fix.
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 08, 2011, 11:24:59 PM

The bug was mine :). It was quite difficult to trace but easy to fix. The OOP zone requires more rigorous testing as there are so many different possible combinations of structures.

Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on July 09, 2011, 10:11:11 AM
There are still problems Charles. I did download the latest in progress version today.

Code: OxygenBasic
  1. sub px( char aChar, sys aNum )
  2.     for x = 1 to aNum
  3.         print aChar
  4.     next
  5. end sub
  6.  
  7. char c = "g"
  8.  
  9. px c, 5

Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 09, 2011, 10:54:04 AM
Hi Kent,

Yes I see the problem. It's picking up the wrong overload function for print when it sees a single zstring . You can get round this by adding another term like ""

Code: OxygenBasic
  1.  
  2. sub px( char* aChar, sys aNum )
  3.     for x = 1 to aNum  
  4.         print achar  ""
  5.     next  
  6. end sub  
  7.  
  8. char c[] = "grail"  
  9.  
  10. px c, 3
  11.  
Title: Re: Can't get my console class to work
Post by: kryton9 on July 09, 2011, 02:40:05 PM
It's just not in printing Charles with overloading. I just wrote this small example to show there is something wrong. It also won't work with a winapi call sending it just a single char as the call wants.
http://msdn.microsoft.com/en-us/library/ms682663(v=vs.85).aspx


Here is a funny return.
Code: OxygenBasic
  1. function px( char aChar, sys aNum ) as string
  2.     string s = ""
  3.     for x = 1 to aNum
  4.         s += aChar
  5.     next
  6.     return s
  7. end function
  8.  
  9. char c = "g"
  10.  
  11. print ">" px( c, 5 ) "<"

I just ran it a couple of times, I guess the answer changes. But the first time I got > 01 01 01 01 01<
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 09, 2011, 03:10:08 PM
Kent I fixed a few more problems likely to show up with chars.

See if it makes any difference. I have checked it against Console and all the other major pieces.

If not then I don't mind tracing the problem in your code.

Charles
Title: Re: Can't get my console class to work
Post by: Peter on July 09, 2011, 03:13:29 PM
Here are you.

function px( char* aChar, sys aNum ) as string 
    string s = "" 
    for x = 1 to aNum 
        s +=  aChar ""
    next 
    return s 
end function 
 
char c = "g" 
 
print ">" + px( c, 5 ) + "<" 

'Result = >ggggg<
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 09, 2011, 03:23:39 PM

Yes well spotted Peter. I was about to say make sure it is char *achar in the prototype.

Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on July 09, 2011, 06:48:54 PM
Thanks Peter and Charles. I did try the * and it was working then, but for a single character why would you need to use *?
It is confusing.

Title: Re: Can't get my console class to work
Post by: kryton9 on July 09, 2011, 07:02:37 PM
The new dll made no difference Charles. I am attaching my code. The method is named Fill and it wraps
sys FillConsoleOutputCharacterA( sys hConsoleOutput, char cCharacter, sys nLength, COORD dwWriteCoord, sys *lpNumberOfCharsWritten )

Hope it helps. Thanks in advance.

outdated attachments removed to avoid any confusion.
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 10, 2011, 12:09:30 AM
Hi Kent

The problem is passing a char directly. Normally one would pass an ascii/unicode code in Basic. But you would have to change char to sys in the declaration.

FillConsoleOutputCharacterA( sys hConsoleOutput, sys cCharacter, sys nLength, COORD dwWriteCoord, sys *lpNumberOfCharsWritten )

I will see if I can fix it so that Oxygen will correctly interpret direct chars as a parameter.


Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on July 10, 2011, 12:41:05 AM
Thanks Charles, I will try sys instead of char in the meantime.
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 10, 2011, 05:17:54 AM
Kent,

'ggg' now appears on your console test screen, now that I have persuaded Oxygen to handle direct char params correctly.

No need to change the prototype :)

Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on July 10, 2011, 09:31:51 AM
That is sweet to see. Thanks Charles!
It is amazing how all of the new console commands are all based on the previous one working. These were some key hold ups this week, but you got them. Thanks again.
Title: Re: Can't get my console class to work
Post by: kryton9 on July 10, 2011, 08:10:10 PM
Sorry to report, some old things that worked are no longer working. See the first post for the latest of my files.
Minor problems in the first 2 test files as noted in the post and in comments in code.

http://www.oxygenbasic.org/forum/index.php?topic=255.msg1544#msg1544
Title: Re: Can't get my console class to work
Post by: kryton9 on July 11, 2011, 09:24:01 PM
Here is another strange problem. It is reading keyevent as wrong characters.
Pressing "x" will exit the program, but if you press other keys you will see the character codes don't match.

This program is console events, keyboard and mouse.

[attachment deleted by admin]
Title: Re: Can't get my console class to work
Post by: Charles Pegge on July 11, 2011, 10:41:48 PM
Hi Kent,

Some tentative fiddling with the structure showed that a 4 byte alignment was required. Oxygen does not currently assume any particular alignment rules except for function address tables. But you can specify an align anywhere within the structure.

To inspect the structure encoding and offsets use:

#recordof KEY_EVENT_RECORD

It is a very useful diagnostic.

Code: OxygenBasic
  1.  
  2. type KEY_EVENT_RECORD
  3.         BOOL bKeyDown
  4.         WORD wRepeatCount
  5.         WORD wVirtualKeyCode
  6.         WORD wVirtualScanCode
  7. align 4
  8.         union uChar
  9.     {
  10.                 WCHAR UnicodeChar
  11.                 CHAR AsciiChar
  12.         }
  13.         DWORD dwControlKeyState
  14. end type
  15.  

Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on July 11, 2011, 11:28:58 PM
Thanks Charles, that will be new stuff for me to study.
Title: Getting Error Now
Post by: kryton9 on November 11, 2011, 08:44:12 PM
Charles, I am getting an error now with the ConsoleC.inc and any of the example programs from the first post.

ERROR:
Invalid constant: anumcharstoread
WORD:    charsread
FILE:    consolec.inc
LINE:    293

I can't figure it out, thanks.
Title: Re: Can't get my console class to work
Post by: Peter on November 12, 2011, 08:57:15 AM
there are only consoles chaos over the christmas days !
the connection:  windows-oxygen-console  runs into a chaos.   
Title: Re: Can't get my console class to work
Post by: Charles Pegge on November 13, 2011, 01:37:09 AM
Hi Kent,

ConsoleC.inc has no errors with the last Oxygen posting (about 6 hous ago) . Have you added more to it recently?

I regularly use the version included in the Oxygen /projects section, for testing :)

Charles
Title: Re: Can't get my console class to work
Post by: kryton9 on November 14, 2011, 01:59:10 PM
Thanks for the reply Charles, I probably downloaded an older version. Sorry about that.
Title: Re: Can't get my console class to work
Post by: efgee on November 14, 2011, 04:47:07 PM
My own console class I had working isn't working anymore either...

Anyway, found one in "OxygenBasic\projects\GLWindow\" and seems to be yours  :)

But it looks like that one is broken as well as Oxygen only accepts constants as array-index:

Code: [Select]
        method GetChrsAt( sys aX, sys aY, sys aNumCharsToRead ) as string
            sys numRead
            char charsRead[aNumCharsToRead]     ' <- ERROR
            COORD crd => ( aX, aY )
            ReadConsoleOutputCharacterA( mhOut, charsRead, aNumCharsToRead, crd, numRead )
            return charsRead
        end method

Oxygen doesn't accept function parameters as array-index anymore ?

Hmm...
Title: Re: Can't get my console class to work
Post by: Charles Pegge on November 15, 2011, 05:35:40 AM
Hi Frank

Oxygen only supports static array declarations, so you have to use a constant to specify the number of elements, not a variable. The memory space for the array is determined at compile time.

This issue escaped detection before, and worked due to a large spurious index value being used.

This is how it now looks in projects/Console/ConsoleC.inc

Code: [Select]
       method GetChrsAt( sys aX, sys aY, sys aNumCharsToRead ) as string
            sys numRead
            char charsRead[256]
            COORD crd => ( aX, aY )
            ReadConsoleOutputCharacterA( mhOut, charsRead, aNumCharsToRead, crd, numRead )
            return charsRead
        end method

Charles

Title: Re: Can't get my console class to work
Post by: efgee on November 15, 2011, 08:50:59 AM
Thanks Charles,
256 chars should be sufficient anyway...
Title: Re: Can't get my console class to work
Post by: Charles Pegge on November 15, 2011, 11:33:09 AM
That is the most efficient solution.

If you need a flexible buffer, or one that is large then use a string:

function bar(sys MaxBytes) as string
string Buf=nuls MaxBytes
sys BytesRead
foo buf,MaxBytes,BytesRead
return left Buf,BytesRead
end function

Code: OxygenBasic
  1.  
  2. function foo(char*z, sys MaxBytes,*BytesRead)
  3. z=left "okay",MaxBytes
  4. BytesRead=len z
  5. end function
  6.  
  7. function bar(sys MaxBytes) as string
  8. string Buf=nuls MaxBytes
  9. sys BytesRead
  10. foo buf,MaxBytes,BytesRead
  11. return left Buf,BytesRead
  12. end function
  13.  
  14.  
  15. sys BytesToRead=1000
  16. print bar (BytesToRead)
  17.  
  18.  

Charles