IonicWind Software

Aurora Compiler => Coding Help - Aurora 101 => Topic started by: ExMember001 on November 15, 2006, 12:22:39 PM

Title: problem with OPENFILE ??
Post by: ExMember001 on November 15, 2006, 12:22:39 PM
i'm getting wrong number of parameters on the openfile line...
well, maybe i'm too tire because i dont see anything wrong ;)


AmpKC::SavePlaylist()
{
int count = PlaylistV->GetCount();
int t;
if count > 0
{
for(t = 0 ; t < count-1 ; t++)
{
string PlaylistFilename = FILEREQUEST("OÃÆ'Ã,¹ Voulez-vous sauvegarder votre playlist?",0, 0,"Fichier Playlist (*.m3u)|*.m3u||");
        if PlaylistFilename <> ""
        {
    string Filen = PlaylistV->GetItemText(t,0);
    string fpath = PlaylistV->GetItemText(t,1);
    UNSIGNED INT PlaylistFile = OPENFILE(PlaylistFilename, MODE_CREATE | MODE_APPEND);
if PlaylistFile <> 0
{
WRITE(PlaylistFile, fpath+Filen, len(fpath+Filen));
}
    closefile(PlaylistFile);
}
}
}
return;
}
Title: Re: problem with OPENFILE ??
Post by: John Syl. on November 15, 2006, 01:01:45 PM
Hi Krypt,

works ok for me.

To test I declared classes and methods that you use and it compiled fine.

here is the code:

class AmpKC
{
declare SavePlayList();
}

Class CPlayListV
{
Declare GetCount(),int;
Declare GetItemText(int t,int n),STRING;
}

CPLayListV::GetCount(),INT
{
int n;
return n;
}

CPLayListV::GetItemText(int t, int n),string
{
string str;
return str;
}


CPlayListV *PlayListV;

AmpKC::SavePlaylist()
{
int count = PlaylistV->GetCount();
int t;
if count > 0
{
for(t = 0 ; t < count-1 ; t++)
{
string PlaylistFilename = FILEREQUEST("OÃÆ'Ã,¹ Voulez-vous sauvegarder votre playlist?",0, 0,"Fichier Playlist (*.m3u)|*.m3u||");
        if PlaylistFilename <> ""
        {
    string Filen = PlaylistV->GetItemText(t,0);
    string fpath = PlaylistV->GetItemText(t,1);
    UNSIGNED INT PlaylistFile = OPENFILE(PlaylistFilename, MODE_CREATE | MODE_APPEND);
if PlaylistFile <> 0
{
WRITE(PlaylistFile, fpath+Filen, len(fpath+Filen));
}
    closefile(PlaylistFile);
}
}
}
return;
}

sub main()
{
return;

}


maybe the problem is further back than you think.

regards
John
Title: Re: problem with OPENFILE ??
Post by: ExMember001 on November 15, 2006, 01:09:07 PM
humm... thanx john ;)

if i comment the above part the program compile but if i uncomment i still get the error...
Title: Re: problem with OPENFILE ??
Post by: ExMember001 on November 15, 2006, 01:19:40 PM
here is the source, its a bass 2.3 Audio Player that support bass formats addons ;)
not much for the moment...

the compiled exe was compiled with the saveplaylist method commented...
in the source code the method is not commented.
Title: Re: problem with OPENFILE ??
Post by: J B Wood (Zumwalt) on November 15, 2006, 01:36:26 PM
Open file = 1, save = 0, anyway, I tried to write up something fast, but... My while statement doesn't loop for some odd reason and no error.


declare cdecl import, debug alias OutputDebugStringA(string str);
global sub main()
{
unsigned int fResult=0;
string Filter = "Text files|*.txt|All Files|*.*||";
int posf=0;
fResult=0;
#break;
string filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
posf = instr(filename,"|");
pointer p1 = filename;
int i=0;
string myList[10];
while (posf)
{
filename[posf-1] = null;
filetemp = *(string)p1;
filename[posf-1] = 32;
p1 = &filename+posf;
myList[i]=filetemp;
posf = instr(filename,"|",posf+1);
debug(myList[i]);
i=i+1;
}
}
Title: Re: problem with OPENFILE ??
Post by: John Syl. on November 15, 2006, 02:36:34 PM
HI Krypt,

found your problem, you have redefined Openfile() in the AmpKC class, therefore this is where it is looking.


regards
John
Title: Re: problem with OPENFILE ??
Post by: ExMember001 on November 15, 2006, 02:43:21 PM
hehe your right ;)
thanx John !
Title: Re: problem with OPENFILE ??
Post by: John Syl. on November 15, 2006, 02:59:28 PM
No problem, it's easy to do.  Get fixed on a train of thought and you ignore all else.
Still finding these probs is what makes it it fun!! ;D
Title: Re: problem with OPENFILE ??
Post by: J B Wood (Zumwalt) on November 15, 2006, 08:40:05 PM
lol, glad you two figured it out, I never got my code to loop again.
Title: Re: problem with OPENFILE ??
Post by: Ionic Wind Support Team on November 15, 2006, 09:23:12 PM
Aurora supports scope resolution.  If you have a class member that is named the same as an external function, or import, you can tell Aurora which one to use.  For example if you have a class named CFile and that class has a method named OpenFile you have to specify which function to call.

CFile::OpenFile(string name, int mode),int
{
      m_hFile = ::OpenFile(name,mode);
      return (m_hFile != NULL);
}

The :: prepended to an identifier instructs the compiler to not resolve to class scope.  If you did not have that then the method would be stuck in an endless loop as it would call itself.

Title: Re: problem with OPENFILE ??
Post by: ExMember001 on November 15, 2006, 09:53:59 PM
interresting, thanx Paul :)
i didnt know that!
Title: Re: problem with OPENFILE ??
Post by: J B Wood (Zumwalt) on November 16, 2006, 06:43:59 AM
This is the only way I could get it to work.

declare cdecl import, debug alias OutputDebugStringA(string str);
global sub main()
{
unsigned int fResult=0;
string Filter = "Text files|*.txt|All Files|*.*||";
int posf=0;
fResult=0;
#break;
string filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
posf = instr(filename,"|");
pointer p1 = filename;
int i=0;
string myList[10];
int isvalid=1;
while (isvalid)
{
filename[posf-1] = null;
filetemp = *(string)p1;
filename[posf-1] = 32;
p1 = &filename+posf;
myList[i]=filetemp;
posf = instr(filename,"|",posf+1);
debug(myList[i]);
if (myList[i]=="")
{
isvalid=0;
}
else
{
i=i+1;
}
}
}


I took Pauls example from the help system and modified it a bit, the example would never show a debug of more than 1 file.
This alteration of the example shows all of the files in debug.
Paul, you might want to snag this code and compile in debug and step through it, there is some interesting step over going on.
Title: Re: problem with OPENFILE ??
Post by: J B Wood (Zumwalt) on November 16, 2006, 08:37:10 AM
Can anyone explain this behavior?

declare cdecl import, debug alias OutputDebugStringA(string str);
global sub main()
{
unsigned int fResult=0;
string Filter = "Text files|*.txt|All Files|*.*||";
int posf=0;
fResult=0;
#break;
string filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
posf = instr(filename,"|");
pointer p1 = filename;
int i=0;
string myList[10];
for (int clean=0;clean<10;clean++)
{
myList[clean]="";
}
int isvalid=1;
int msg=0;
string tmpStr="";

while (isvalid)
{
filename[posf-1] = null;
filetemp = *(string)p1;
filename[posf-1] = 32;
p1 = &filename+posf;
tmpStr=TRIMRIGHT(filetemp);

if (tmpStr != "")
{
myList[i]=filetemp;
posf = instr(filename,"|",posf+1);
debug(myList[i]);
i++;
}
else
{
isvalid=0;
}
}

for (int k=0;k<10;k++)
{
tmpStr=TRIMRIGHT(myList[k]);
if (tmpStr == "")
{
k=10;
}
else
{
msg=MessageBox(NULL,myList[k],"Current File",MB_OK);
}
}
}


I can at most get 3 files to show in messagebox result.
If I select more than 3, I get :

AppName: fileexample.exe    AppVer: 0.0.0.0    ModName: unknown
ModVer: 0.0.0.0    Offset: 445c3a43

Now, I know what you might say, which is to increase the string length.
filename[posf-1] = 32;

I tried to modify that and didn't make any difference, I changed it to upwards around 1024 to see if that helped, but still the same problem.
What am I missing?
Title: Re: problem with OPENFILE ??
Post by: Ionic Wind Support Team on November 16, 2006, 11:29:14 AM
>>>>string filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);

A string type is only 255 characters long.  The maximum path length in windows is 260 characters.  So you need a bigger buffer.

dstring filename[260 * 100]; //allow up to 100 files to be selected
filename = FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);

Better yet allocate the buffer with NEW.
Title: Re: problem with OPENFILE ??
Post by: J B Wood (Zumwalt) on November 16, 2006, 02:42:51 PM
How do you mean use NEW?
Sorry, I don't typically work with buffers.
NEW doesn't work on variables I thought.
The above mentioned changed in my code doesn't work for 10 files, so I will look it over tonight to see if I can comprehend this.
Title: Re: problem with OPENFILE ??
Post by: Ionic Wind Support Team on November 16, 2006, 02:50:40 PM
NEW allocates memory.  It returns a pointer to that memory.  It doesn't care what the memory is used for. 

string *buffer = new(byte, 10000);  //a 10K string

*buffer = "hello";
*buffer = FileRequest....

etc.

The change I gave you was just because you would be overwritting the buffer after 255 characters and it was the most glaring error.  I haven't looked at the rest of your code, you may have other errors.

Title: Re: problem with OPENFILE ??
Post by: Ionic Wind Support Team on November 16, 2006, 04:23:29 PM
Is this what you're looking for?  Simplified it a bit.


declare import,ZeroMemory alias RtlZeroMemory(void *mem,int count),int;
global sub main()
{
openconsole();
unsigned int fResult=0;
string Filter = "Text files|*.txt|All Files|*.*||";
dstring filename[260*10]=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
int posf = instr(filename,"|");
pointer p1 = filename;
int i=0;
string myList[10];
ZeroMemory(mylist,10*255);
int isvalid = (posf != 0);
int msg=0;
string tmpStr="";

while (isvalid)
{
filename[posf-1] = null;
filetemp = *(string)p1;
filename[posf-1] = 32;
p1 = &filename+posf;
if (filetemp != "")
{
myList[i]=filetemp;
posf = instr(filename,"|",posf+1);
print(myList[i]);
if(i < 9) i++ else break;
}
else
{
isvalid=false;
}
}

for (int k=0;k<10;k++)
{
if (myList[k] == "")
{
k=10;
}
else
{
msg=MessageBox(NULL,myList[k],"Current File",MB_OK);
}
}
while GetKey() = "";
}
Title: Re: problem with OPENFILE ??
Post by: Ionic Wind Support Team on November 16, 2006, 04:26:59 PM
And this one shows the same code allocating the buffer with NEW


declare import,ZeroMemory alias RtlZeroMemory(void *mem,int count),int;
global sub main()
{
openconsole();
unsigned int fResult=0;
string Filter = "Text files|*.txt|All Files|*.*||";
string *filename = new(byte,260*100);
*filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
int posf = instr(*filename,"|");
pointer p1 = filename;
int i=0;
string myList[10];
ZeroMemory(mylist,10*255);
int isvalid = (posf != 0);
int msg=0;
string tmpStr="";

while (isvalid)
{
*filename[posf-1] = null;
filetemp = *(string)p1;
*filename[posf-1] = 32;
p1 = filename+posf;
if (filetemp != "")
{
myList[i]=filetemp;
posf = instr(*filename,"|",posf+1);
print(myList[i]);
if(i < 9) i++ else break;
}
else
{
isvalid=false;
}
}

for (int k=0;k<10;k++)
{
if (myList[k] == "")
{
k=10;
}
else
{
msg=MessageBox(NULL,myList[k],"Current File",MB_OK);
}
}
delete filename;
while GetKey() = "";
}
Title: Re: problem with OPENFILE ??
Post by: Ionic Wind Support Team on November 16, 2006, 04:46:13 PM
And since I am an advocate of simplifcation.  This final example of your code uses a CStringList to store the filenames and allows selecting up to a 100 files.


global sub main()
{
OpenConsole();
string Filter = "Text files|*.txt|All Files|*.*||";
//select up to 100 files.
string *filename = new(byte,260*100);
*filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
int posf = StrFind(*filename,"|");
string *p1 = filename;
CStringList myList;
myList.Create();

while (posf)
{
*filename[posf-1] = NULL;
filetemp = *p1;
*filename[posf-1] = ' ';
p1 = filename+posf;
if (filetemp[0] != NULL)
{
myList.Add(filetemp);
posf = StrFind(*filename,"|",posf+1);
print(filetemp);

}
else
break;
}
int count = 0;
for (pointer k=myList.GetFirst(); k; k = myList.GetNext(k))
{
MessageBox(NULL,myList.GetData(k),"Current File",MB_OK);
count++;
}
print("You Selected: ",count," file(s)");
delete filename;
myList.RemoveAll(true);
while GetKey() = "";
}
Title: Re: problem with OPENFILE ??
Post by: Kale on November 16, 2006, 04:58:51 PM
It's just occured to me that instead of doing this:


for (pointer k=myList.GetFirst(); k; k = myList.GetNext(k))
{
    MessageBox(NULL,myList.GetData(k),"Current File",MB_OK);
    count++;
}


it would be nice to do something along these lines:


foreach(myList, myItem)
{
    MessageBox(NULL,myList.GetData(myItem),"Current File",MB_OK);
    count++;
}


or


foreach(*myList, *myItem)
{
    MessageBox(NULL,myList->GetData(*myItem),"Current File",MB_OK);
    count++;
}


any chance of that? ;D
Title: Re: problem with OPENFILE ??
Post by: ExMember001 on November 16, 2006, 08:49:25 PM
Quote from: Kale on November 16, 2006, 04:58:51 PM
It's just occured to me that instead of doing this:


for (pointer k=myList.GetFirst(); k; k = myList.GetNext(k))
{
    MessageBox(NULL,myList.GetData(k),"Current File",MB_OK);
    count++;
}


it would be nice to do something along these lines:


foreach(myList, myItem)
{
    MessageBox(NULL,myList.GetData(myItem),"Current File",MB_OK);
    count++;
}


or


foreach(*myList, *myItem)
{
    MessageBox(NULL,myList->GetData(*myItem),"Current File",MB_OK);
    count++;
}


any chance of that? ;D

In term of Simplification i think it's a good one ;)
Title: Re: problem with OPENFILE ??
Post by: Steven Picard on November 16, 2006, 09:10:17 PM
I agree with you guys.  That looks like nice, simple syntax. :)
Title: Re: problem with OPENFILE ??
Post by: Ionic Wind Support Team on November 16, 2006, 09:35:09 PM
Except it wouldn't work with OOP list classes,  'foreach' is a BASIC keyword anyway and I am not going to overly alter the syntax of Aurora before the 1.0 release. 

The FOR statement was used here as an example, because FOR in Aurora is much more than a counter.  You can also use other methods such as a WHILE loop, or even a dynamic array class, and it wasn't even related to the original problem ;)

Title: Re: problem with OPENFILE ??
Post by: Kale on November 17, 2006, 01:09:30 AM
Quote from: Paul Turley on November 16, 2006, 09:35:09 PM
Except it wouldn't work with OOP list classes,  'foreach' is a BASIC keyword anyway and I am not going to overly alter the syntax of Aurora before the 1.0 release. 
The FOR statement was used here as an example, because FOR in Aurora is much more than a counter.  You can also use other methods such as a WHILE loop, or even a dynamic array class, and it wasn't even related to the original problem ;)

Yeah it was a bit off topic ;) but i was just thinking about simplifying iterating through linked lists. ;D
Title: Re: problem with OPENFILE ??
Post by: J B Wood (Zumwalt) on November 17, 2006, 06:58:29 AM
What I was asking was related to the original problem in an indirect way, it had to do with the Method that was being used.
I'll start a new thread next time then if you want, even if it relates to the same method.
All I was trying to do was take the docs example and elaborate to show how to fix his original problem, and ran into a problem of my own, and didn't think I should have started a new thread.

A string value in Windows ironiaclly is 2 gig in size not 255 characters. 255 characters is a limitation for Aurora, and rightly so, because a string at 255 is optimized, a string in Microsoft .Net for example is an array of unicode characters, this array is dynically created. A string as I understand it in Aurora is a fixed length of unicode characters at 255. That was my first understanding when reading this topic that we are working on.

What I did not know for sure until now, is that Aurora had a fixed length for a string, now I know.
Sorry for confusing the topic.
Title: Re: problem with OPENFILE ??
Post by: Ionic Wind Support Team on November 17, 2006, 10:07:45 AM
WSTRING is the Aurora unicode string.  DWSTRING is the dimensionable unicode string.  As mentioned in the tutorial included with the help. 

Quote
A string value in Windows ironiaclly is 2 gig in size not 255 characters.

Were did you get that idea?.  Windows doesn't have a string type, or any types at all for that matter.  The API uses NULL terminated strings the same as the C runtime.  COM uses a system string which is allocated dynamically, like we do with NEW.

I mention the C runtime because technically C and C++ don't have a string type at all.  In C++ a string type is provided by a class, or template, not by the compiler.  In C a string is a character array and all of the string capabilities are contained in a library. 

Quote
What I did not know for sure until now, is that Aurora had a fixed length for a string, now I know.

No it just has the convenience of allocating a 255 byte one when you use STRING name or a 255 character one when using WSTRING name.  A DSTRING is a keyword meaning "dimension a string".

dstring name[30000]; // a 30K string

Of course if you're really into dynamic string you can use NEW.

string *name = new(byte, 1000000); // A million byte string.

Lots of choices built in.

Paul.
Title: Re: problem with OPENFILE ??
Post by: J B Wood (Zumwalt) on November 17, 2006, 11:37:40 AM
As I mentioned, in .Net, its a collection of unicode characters:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasstopic.asp
Thats where I got that idea.
The maximum size of the string object is or was 2 gig.
When you create a string object, and don't give it an intial value, you are in essance creating a 2 byte empty object. (null)
When you add a value to that object, it creates a new object replacing the original object and its size is equal to the number of unicode characters you add.
The maximum size I had read a long time ago for the 2 gig max length for the string (2 gig of unicode characters), although I could be sadly mistaken.
Title: Re: problem with OPENFILE ??
Post by: Ionic Wind Support Team on November 17, 2006, 12:14:59 PM
Thats .NET not Windows.  Windows itself is just an OS and doesn't have types.  .NET is a runtime used by Microsoft (and a few other) languages.  My point was the string class in .NET is provided by the runtime, not by the language which uses it.  And the class isn't really a type either, it is a dynamic object.

You could create your own string class in Aurora if you want.  There is an example of a dynamic array class included with Aurora, oop1.src, which can be modified to support any data type.  Just remember memory allocations and deletions add overhead to your program.  If you're looking for speed and you're doing a ton of text processing then you want to stay away from excessive memory allocations.

That is the one thing that irks me about bloated runtimes, sure they add a ton of convenience but they make for poor programmers.  Especially if the programmer has never had to do it for themselves before.  You go through school and all they teach is C# and Java.  Then you're employed by a company that doesn't want you to use .NET because their product has to be cross platform, and quickly. If you don't know the basics of data types, type sizes, and data algorythms you are screwed. 

The Aurora compiler has built in types that are not based on a runtime but directly generated in assembly code.  The compiler natively knows what a string is and can concatenate two strings without having to use a class.  It does this for both speed and size.

Paul.