I've just updated the alpha. Hope the three of you that have purchased saved the download link ;)
Changes/Additions:
-break; command added for FOR and WHILE loops
-#define now works for constants and conditional compiling. Helps when converting C header files.
#define WM_USER 0x400
-Better error checking.
-Removed some syntax conficts dealing with the '*'
-Very simple OOP.
You can now define a class, it's member funcitons (methods) , and class variables. It's not fully complete yet as the code for calling constructors/destructors isn't in there yet. I'll post an example shortly.
Paul.
The promised OOP example. An integer array that manages its own memory and can grow as needed in size. Probably not completely bug free but it works.
The class functions could be compiled in a separate source file and the class definition placed in an include file.
[edit] Code modified see further down
I compiled this example and it completely crashed on me as soon as it launched. I'm using Windows XP SP2. Just let me know if you need more info about my computer setup.
Compile a debug mode and go. See where it stops.
I may have munged up a library when building the installation. Anyone else care to test?
Works just fine here on my PC. (XP Home w/SP2)
-Doc-
Crashes for me XP SP2
Will try to get an error report.
Here's were it crashed:
GlobalFree(m_mem);
The thread 'Win32 Thread' (0xcc8) has exited with code 0 (0x0).
Unhandled exception at 0x004053d3 in class example.exe: 0xC0000005: Access violation reading location 0x00000018.
If I run it using the debug icon on the toolbar it doesn't crash.
Same here. Runs okay when I click on Debug.
I just re-compiled after checking to make sure debug mode was off (it was) and got the same results as the first time...
...no problems on this end.
Maybe a reboot is in order? (stranger things happen ya know)
-Doc-
Which GlobalFree statement?
Quote from: Ionic Wizard on November 06, 2005, 06:10:53 PM
Which GlobalFree statement?
Whoops! That wasn't too helpful of me. Line 86.
Error in my logic somewhere and you have fragmented memory ;)
Give me a sec...
Quote from: Ionic Wizard on November 06, 2005, 06:27:52 PM
...and you have fragmented memory ;)
Sorry, what were we talking about again? ??? ;D
BTW, do you know of a good free app for defraging memory??
Try this:
//simple example of using objects in Aurora
declare import,GlobalAlloc(flags as unsigned int,size as int),unsigned int;
declare import,GlobalReAlloc(handle as unsigned int,size as int,flags as unsigned int),unsigned int;
declare import,GlobalFree(handle as unsigned int),int;
declare import,RtlMoveMemory(dest as int,source as int,size as int);
class IntArray {
//the class constructor
declare IntArray();
//the class destructor
declare _IntArray();
//member functions
declare GetAt(int pos),int;
declare SetAt(int pos,int value);
declare SetAtGrow(int pos,int value);
declare SetSize(int size);
declare GetCount(),int;
declare RemoveAll();
//member variables
int m_mem;
int m_GrowBy;
int m_numItems;
int m_allocated;
}
IntArray :: IntArray()
{
m_GrowBy = 10;
m_mem = GlobalAlloc(0x40,m_GrowBy * 4);
m_numItems = 0;
m_allocated = 10;
return;
}
IntArray :: _IntArray()
{
//clean up our object
if(m_mem)
{
GlobalFree(m_mem);
m_mem = NULL;
}
m_numItems = 0;
m_allocated = 0;
return;
}
IntArray :: GetAt(int pos),int
{
if pos < m_numItems
{
return *(int)(m_mem + (pos * 4));
}
return 0;
}
IntArray :: SetAt(int pos,int value)
{
if(pos < m_allocated)
{
*(int)(m_mem + (pos * 4)) = value;
if((pos+1) > m_numItems)
{
m_numItems = pos+1;
}
}
return;
}
IntArray :: SetAtGrow(int pos,int value)
{
unsigned int temp;
int total;
if( (pos + 1) > m_allocated)
{
//calculate how many blocks to allocate
total = (pos+1) - m_allocated;
total = (total & m_GrowBy) + 1;
total *= m_GrowBy;
//Grow the array
temp = GlobalRealloc(m_mem,(m_allocated + total) * 4,0x40);
if(temp)
{
m_mem = temp;
}
else
{
//could not reallocate so copy
temp = GlobalAlloc(0x40,(m_allocated + total) * 4);
RtlMoveMemory(temp,m_mem,m_allocated * 4);
GlobalFree(m_mem);
m_mem = temp;
}
m_allocated += m_GrowBy;
}
*(IntArray)this.SetAt(pos,value);
return;
}
IntArray :: SetSize(int size)
{
unsigned int temp;
if(size > m_allocated)
{
temp = GlobalRealloc(m_mem,(size - m_allocated) * 4,0x40);
if(temp)
{
m_mem = temp;
}
else
{
temp = GlobalAlloc(0x40,(size - m_allocated) * 4);
RtlMoveMemory(temp,m_mem,m_allocated * 4);
GlobalFree(m_mem);
m_mem = temp;
}
m_allocated = size;
}
return;
}
IntArray :: GetCount(),int
{
return m_numItems;
}
IntArray :: RemoveAll()
{
if(m_allocated)
{
GlobalFree(m_mem);
m_allocated = 10;
m_numItems = 0;
m_mem = GlobalAlloc(0x40,m_GrowBy * 4);
}
return;
}
//test program for Intarray class
global sub main(),int
{
IntArray ia;
//temporary until constructors work
ia.IntArray();
for x=0;x < 100;x++
{
ia.SetAtGrow(x,RAND(100));
}
writeln("array has :" + str$(ia.GetCount(),0) + " items\n");
writeln("Press any key to show array contents\n");
while GetKey() = "";
//now lets show what we did.
for x=0;x < ia.GetCount();x++
{
writeln(str$(ia.GetAt(x),0));
}
writeln("\n\n");
ia.RemoveAll();
writeln("array now has :" + str$(ia.GetCount(),0) + " items\n");
writeln("Press any key close\n");
while GetKey() = "";
//temporary until destructors work
ia._IntArray();
return 0;
}
RtlMoveMemory was declared wrong, and my logic for growing was a bit off.
Quote from: stevenp on November 06, 2005, 06:36:48 PM
Quote from: Ionic Wizard on November 06, 2005, 06:27:52 PM
...and you have fragmented memory ;)
Sorry, what were we talking about again? ??? ;D
BTW, do you know of a good free app for defraging memory??
Nope. Use the Ctrl-Alt-Delete method myself ;)
Excellent! Worked great. But was it supposed to format my hard drive? J/K
Works now.
I don't get it...
How could two out of three of us have had problems with the exact same code, especially when both samples work on my end? :-\
I know I'm more than a little bit "different", but geesh..
-Doc-
QuoteNope. Use the Ctrl-Alt-Delete method myself ;)
All hail to the old three finger salute! ;D
-Doc-
Hi,
Just tried this example, due to the time difference. Works OK for me, XP Pro, SP2
Brian
Quote from: docmann on November 06, 2005, 06:51:02 PM
I don't get it...
How could two out of three of us have had problems with the exact same code, especially when both samples work on my end? :-\
I know I'm more than a little bit "different", but geesh..
-Doc-
GlobalRealloc will fail if memory is overly fragmented. Which then drops into the other part of the code to allocate a new block of memory and copy the contents of the array. Your system and mine worked because GlobalRealloc succeeded.
Paul,
Any chance of an example with a window, with maybe a menu and button, etc?
Brian
Quote from: Brian Pugh on November 07, 2005, 06:57:04 AM
Paul,
Any chance of an example with a window, with maybe a menu and button, etc?
Brian
Brian, I don't think the GUI is supposed to be completed until Beta 1:
http://www.ionicwind.com/forums/index.php?topic=18.0
Whoops! Should have RTFM'd!
Still designing the GUI commands. The alphas are to shake down the syntax, check for glaring bugs, etc.
You can use the API directly if you really need to see a window pop up ;) Alpha 2 will have the start of the GUI commands.
I have been toying with the idea of an oop hybrid for the GUI libray. Something along the lines of:
window win;
win.CreateWindow(0,0,100,300,style,exstyle,title);
win.DrawRect(10,10,50,50,fg,bg);
...
Then you could have two choices of how to handle messages.
#1 Inherit from the window class. Those of you that don't know oop will need a little help.
class mainwindow : window
{
declare virtual OnMouseMove(int x, int y, int flags);
declare virtual OnLbuttonDown(int x, int y, int flags);
...
}
mainwindow :: OnMouseMove(int x, int y, int flags)
{
//handle mouse move messages for our mainwindow.
}
mainwindow.CreateWindow(0,0,100,300,style,exstyle,title);
For those of you that have only used procedural languages OOP allows inheriting all of the functions and capabilities of the base class. In the case above we created a new class called 'mainwindow' whose base class was 'window'. We only need to override the functions in the base class we want to use. In the base 'window' class there would be virtual functions of the same name that do nothing.
#2. A hybrid merging of worlds. Using just the window class I could have a function like:
win.SetExternalHandler(&myhandler);
sub myhandler(msg as uint, ...)
{
}
In anyevent I am just thinking out loud.
Either would be excellent although I prefer the first one. 8)
Paul, your grasp of these things is awesome ..ÂÃ, :)
Pick whichever you think is most elegant.
best wishes, :)
Graham
I don't know that I would have a preference either way.
QuoteThose of you that don't know oop will need a little help
Being a cross-platform language with a distinctive "C-like" syntax, Aurora I believe, will eventually be (for me at least) that "serious" new language tool that will be well worth the learning curve... whatever that may be.
-Doc-
I would prefer the first method since it is more what I am use to and is probably more standard.
Quote from: docmann on November 07, 2005, 04:46:26 PM
....Aurora I believe, will eventually be (for me at least) that "serious" new language tool that will be well worth the learning curve... whatever that may be.
I am with you on that.