strings.bas compile -dll
Code: Select all
'strings.bas compile with -dll switch
Enum
up
down
End Enum
type strings
as string original
as string sorted
as byte direction
declare constructor
declare constructor(as string, as byte,as long,as long)
declare function sort(as strings,as long,as long) as string
end type
constructor strings export
end constructor
constructor strings(tosort as string, dirn as byte,l as long,u as long) export
original=tosort
direction=dirn
sorted=sort(this,l,u)
end constructor
function strings.sort(ss As strings,begin As Long,Finish As Long) as string
static as strings s:s=ss
Dim As Long i=begin,j=finish
Dim As ubyte x =S.original[(I+J)\2]
While I <= J
if direction=down then
While S.original[I] > X:I+=1:Wend
While S.original[J] < X:J-=1:Wend
else
While S.original[I] < X:I+=1:Wend
While S.original[J] > X:J-=1:Wend
end if
If I<=J Then Swap S.original[I],S.original[J]: I+=1:J-=1
wend
If J > begin Then sort(S,begin,J)
If I < Finish Then sort(S,I,Finish)
return s.original
End function
Code: Select all
#inclib "strings"
Enum
up
down
End Enum
type strings
as string original
as string sorted
as byte direction
declare constructor
declare constructor(as string, as byte,as long,as long)
end type
dim as string f="FreeBASIC example of dynamic library file for exported constructors (.dll)"
dim as strings g
g=type(f,up,0,len(f)-1)
print g.original
print g.sorted
print
g=type(f,down,0,len(f)-1)
print g.original
print g.sorted
print
g=type("0123456789",down,0,9)
print g.sorted
print "Done"
sleep