From some reason this gets memory access violation
Archives Forums/BlitzMax Bug Reports/From some reason this gets memory access violation
| ||
Type Test
Field AText:String
Method Mainer(Data:String)
AText = Data
Req()
Function Req()
Print AText
End Function
End Method
End Type
Local TT:Test = New Test
TT.Mainer("amiga")
I was just challanging the system I know its recursive but it get stuck even before it prints one time also I had a weird print result when i did this code
Strict
'------Command Extender ------'
'45 * (90 + 3 / 4)
Type CmdExtender_Class
Field CommandName:String
Field CSParent:CmdExtender_Class
Field SubCommands:TList = CreateList()
Field CommandText:String
'Abstracts
Method ParsePrivate:String() Abstract 'parsePrivate an Action
'Main Parser
Method MainParseProcess(Text:String, Command:CmdExtender_Class, Debug = False)
'Charge
CommandText = Text
'Command Loop
Repeat
Req_MainParseProcess(Command, Debug)
Until CommandText = ""
Function Req_MainParseProcess:String(Command:CmdExtender_Class, Debug = False)
Local TextChunk:String
If Command <> Null Then
'Take Chunk
TextChunk = Command.ParsePrivate()
Print CommandText
If TextChunk <> "" Then
'SubCommands Parse
Local TempCommand:CmdExtender_Class, Answer:String
For TempCommand = EachIn Command.SubCommands
If CommandText <> "" Then Answer = Req_MainParseProcess(TempCommand, Debug)
If Answer <> "" Then Exit
Next
If Debug Then
Print "Remaind Text: " + CommandText + " TextChunk: " + TextChunk
Delay (200)
End If
End If
End If
Return TextChunk
End Function
End Method
'Add Command
Method AddNewCommandAsSon:CmdExtender_Class(Command:CmdExtender_Class, Parent:CmdExtender_Class = Null)
Local NewCell:CmdExtender_Class
NewCell = New Command
NewCell.CSParent = Parent
Int_CommandAdding(NewCell, Parent)
Return NewCell
End Method
Method AddExistingCommandAsSon(Cmnd:CmdExtender_Class, ParentCmnd:CmdExtender_Class)
Int_CommandAdding(Cmnd, ParentCmnd)
End Method
Method Int_CommandAdding(Cmnd:CmdExtender_Class, ParentCmnd:CmdExtender_Class)
If ParentCmnd = Null Then
ListAddLast(SubCommands, Cmnd)
Else
ListAddLast(ParentCmnd.SubCommands, Cmnd)
End If
End Method
'---Debug---'
Method DisplayStructure()
End Method
End Type
'Example: Name/Dan|2/45
'Example: 45*(90+3/4)
'-----------------SubCommands Tests---------------'
'---MathProcess---'
Type Proc_Math_Class Extends CmdExtender_Class
Method New()
CommandName = "Proc_Math_Class"
'Command Acceptence
AddNewCommandAsSon(New Sign_Number_Class)
AddNewCommandAsSon(New Sign_Multiply)
AddNewCommandAsSon(New Proc_Brackets)
AddNewCommandAsSon(New Sign_Devide)
End Method
Method ParsePrivate:String()
Return CommandText
End Method
End Type
Type Proc_Brackets Extends CmdExtender_Class '()
Method New()
End Method
Method ParsePrivate:String()
Local I, Answer:String
If Left(CommandText, 1) = "(" Then
For I = 2 To Len(CommandText)
If Mid(CommandText, I, 1) = ")" Then
Answer = Mid(CommandText, 2, I - 2)
CommandText = Right(CommandText, Len(CommandText) - I)
Return Answer
End If
Next
End If
End Method
End Type
'Subs
Type Sign_Number_Class Extends CmdExtender_Class
Method ParsePrivate:String()
Local I, Answer:String
For I = 1 To Len(CommandText)
If Left(CommandText, 1) = "-" Or Left(CommandText, 1) = "+" Then I = I + 1
If ChrarecterFound(Mid(CommandText, I, 1), ".0123456789") <> True Then
Answer =Left(CommandText, I - 1)
CommandText = Right(CommandText, Len(CommandText) - (I - 1))
Return Answer
End If
Next
End Method
'-------------'
Method ChrarecterFound(Text:String, ChrsList:String) 'Looks from a list of charecters and return true found
Local I,J,LenChrs,CurrentChr$
LenChrs=Len(ChrsList)
For I=1 To LenChrs
CurrentChr=Mid(ChrsList,I,1)
For J=1 To Len(Text)
If Mid(Text,J,1)=CurrentChr Then Return True
Next
Next
End Method
End Type
'Signs
Type Sign_Minus Extends CmdExtender_Class '-
Method parsePrivate:String()
If Left(CommandText, 1) = "-" Then
CommandText = Right(CommandText, Len(CommandText) - 1)
Return "-"
End If
End Method
End Type
Type Sign_Plus Extends CmdExtender_Class '+
Method parsePrivate:String()
If Left(CommandText, 1) = "+" Then
CommandText = Right(CommandText, Len(CommandText) - 1)
Return "+"
End If
End Method
End Type
Type Sign_Multiply Extends CmdExtender_Class '*
Method parsePrivate:String()
If Left(CommandText, 1) = "*" Then
CommandText = Right(CommandText, Len(CommandText) - 1)
Return "*"
End If
End Method
End Type
Type Sign_Devide Extends CmdExtender_Class '/
Method parsePrivate:String()
If Left(CommandText, 1) = "/" Then
CommandText = Right(CommandText, Len(CommandText) - 1)
Return "/"
End If
End Method
End Type
'-------DataBase-------'
'-----Test Area-----'
Global math:Proc_Math_Class = New Proc_Math_Class
math.MainParseProcess("-45*(90+30/40)", New Proc_Math_Class, True)
its like he returns the internal process. haha funny and weird Button Line I cant trust Funtions inside a method after this test |
| ||
| Hiya, Functions within Types have no real association to the Type other than its scope level. The members of the Type are not available to the Function and you should pass in an instance of the Type as a parameter. It's strange that it 'kinda' works and bugs out as the compiler should really pick up these type of errors during compilation. For eg...
Type Test
Field AText:String
Method Mainer(Data:String)
AText = Data
Req(Self)
Function Req(Instance:Test)
Print Instance.AText
End Function
End Method
End Type
Local TT:Test = New Test
TT.Mainer("amiga")
|
| ||
| Second code even weirder. Dont try to understand it. Its a mess. But the result is funny |
| ||
| Dont try to understand it. Its a mess. Doesn't look so bad. It can initially look confusing when you're using inheritance, although a little tidy up will help with debugging. We're programmers and the temptation to not look through the code is just too much :P Especially as it does die so spectacularly! [EDIT] The error is no doubt caused by the 'Function within Type' scenario as I explained above. |