Nope it wasn't a bug in free basic... well maybe sort of it was... hehehehe.
Free basic is designed a bit weird...
get and put parameters are a bit weird and inconsistent... but it's ok... I
finally figured it out...
Ammount means "number of variables" and not "number of bytes"...
So all I need to do to make the read integer function work is set ammount to
1 to read one integer.. otherwise a buffer overrun would probably occur !
(Good thing windows has memory protection ! ;) It warned many times...)
Now the issue should be fixed here is full code with examples for read
functions:
(Now I should be done in a snap... no fixing required for my code so that's
cool... )
I was beginning to loose faith in freebasic.... but it appears to work.
So far there are a couple of things that I find instatisfactory:
1. if...then, the "then" is not needed and could be scrapped from the
language, or made optional that would code most more pleasantly.
2. get/put functions weird.
3. no debugger... but in a way... having no debugger is kinda interesting...
this forces me to read the documentation over and over until I find the
solution... with a debugger I might have been wasting more time try to
figure out what's going on ! LOL ;) :)
rem *** start of code ***:
const false = 0
const true = 1
function ReadByteFromStream( ParaStream as integer, byref ParaByte as byte )
as integer
dim vBytesRead as integer
get #ParaStream, ,ParaByte, 1, vBytesRead
if vBytesRead = SizeOf(byte) then return true
return false
end function
function ReadShortFromStream( ParaStream as integer, byref ParaShort as
short ) as integer
dim vBytesRead as integer
get #ParaStream, ,ParaShort, 1, vBytesRead
if vBytesRead = SizeOf(short) then return true
return false
end function
function ReadIntegerFromStream( ParaStream as integer, byref ParaInteger as
integer ) as integer
dim vBytesRead as integer
get #ParaStream, ,ParaInteger, 1, vBytesRead
if vBytesRead = SizeOf(integer) then return true
return false
end function
function ReadLongintFromStream( ParaStream as integer, byref ParaLongint as
longint ) as integer
dim vBytesRead as integer
get #ParaStream, ,ParaLongint, 1, vBytesRead
if vBytesRead = SizeOf(longint) then return true
return false
end function
function ReadFromStream( ParaStream as integer, ParaBuffer as any ptr,
ParaSize as integer ) as integer
dim vBytesRead as integer
get #ParaStream, ,*CPtr( byte ptr, ParaBuffer ), ParaSize, vBytesRead
return vBytesRead
end function
sub main
dim vLongint as longint
dim vInteger as integer
dim vWord as short
dim vByte as byte
dim vFileStream as integer
rem find first free file handle
vFileStream = freefile
rem open "test.dat" as binary filestream
open "test.dat" for binary as #vFileStream
dim vBytesRead as integer
if true = false then
Seek vFileStream, 1
vBytesRead = ReadFromStream( vFileStream, @vLongint, SizeOf(longint) )
print using "bytes read: ## value: ##################"; vBytesRead,
vLongint
vBytesRead = ReadFromStream( vFileStream, @vInteger, SizeOf(integer) )
print using "bytes read: ## value: ###############"; vBytesRead,
vInteger
vBytesRead = ReadFromStream( vFileStream, @vWord, SizeOf(ushort) )
print using "bytes read: ## value: ###########"; vBytesRead, vWord
vBytesRead = ReadFromStream( vFileStream, @vByte, SizeOf(ubyte) )
print using "bytes read: ## value: #####"; vBytesRead, vByte
sleep
seek vFileStream, 1
endif
if ReadLongintFromStream( vFileStream, vLongint ) = true then
print using "longint read: ###################"; vLongint
endif
if (ReadIntegerFromStream( vFileStream, vInteger ) = true) then
print using "integer read: ##########"; vInteger
endif
if (ReadShortFromStream( vFileStream, vWord ) = true) then
print using "word read: #####"; vWord
endif
if (ReadByteFromStream( vFileStream, vByte ) = true) then
print using "byte read: ###"; vByte
endif
rem extra parenthesis don't matter ;)
if (ReadLongintFromStream( vFileStream, vLongint ) = true) then
print using "longint read: ###################"; vLongint
endif
if (ReadIntegerFromStream( vFileStream, vInteger ) = true) then
print using "integer read: ##########"; vInteger
endif
if ReadShortFromStream( vFileStream, vWord ) = true then
print using "word read: #####"; vWord
endif
if ReadByteFromStream( vFileStream, vByte ) = true then
print using "byte read: ###"; vByte
endif
rem close binary filestream
close #vFileStream
end sub
main
print "press enter to terminate"
rem wait for a key press
sleep
rem *** end of code ***
Bye,
Skybuck.