linus Posted July 9, 2010 Share Posted July 9, 2010 Hope this was not asked before, but I have a question about usability: is there a trick to use scite's auto-complete for objects? To be more precise: I would like to use something like c-style typedefs in an UDF. This should be possible with autoItobject if I am not completely wrong. But it would be much more user-friendly if it's not necassary to memorise all the included properties but to have code-completion for e.g. $myObj.veryLongPropertyNameWhichIsHardToMemorise ...I got scite configured (in au3.properties) to notice call tips with leading dot, but this works only behind a blank, not after the $myObj ...? Link to comment Share on other sites More sharing options...
Kip Posted July 9, 2010 Share Posted July 9, 2010 Hope this was not asked before, but I have a question about usability: is there a trick to use scite's auto-complete for objects? To be more precise: I would like to use something like c-style typedefs in an UDF. This should be possible with autoItobject if I am not completely wrong. But it would be much more user-friendly if it's not necassary to memorise all the included properties but to have code-completion for e.g. $myObj.veryLongPropertyNameWhichIsHardToMemorise ...I got scite configured (in au3.properties) to notice call tips with leading dot, but this works only behind a blank, not after the $myObj ...?The object type isn't known to the editor, that means it will have to list all the members of all the objects available.I don't know whether it's possible in SciTE, but it wouldn't make much sense to me. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
linus Posted July 10, 2010 Share Posted July 10, 2010 (edited) The object type isn't known to the editor, that means it will have to list all the members of all the objects available.I don't know whether it's possible in SciTE, but it wouldn't make much sense to me.Yes, only useful if there would be a way to get ".veryLongPropertyNameWhichIsHardToMemorise" working for code-completion WITHOUT leading "$myobj". Adding ALL combinations of objects + members used in a specific sript to the usercalltips-file would be stupid - and also impossible (except maybe for "constant" objects used in the UDF). Was just wondering if there is a tricky way to configure sciTe this way, since I got at least "dot"something working for code completion - by adding a dot in au3.properties behind default autocomplete.au3.start.characters=$(chars.alpha)$(chars.numeric)$_@#. But still useless until it needs a leading blank to be recognised by sciTe. Edited July 10, 2010 by linus Link to comment Share on other sites More sharing options...
KaFu Posted August 4, 2010 Share Posted August 4, 2010 Taking a look at jaberwockys ImageMagickObject using AutoItObject I wonder if I could use AutoItObject to implement an interface to IExtractImage. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
doudou Posted August 5, 2010 Share Posted August 5, 2010 Taking a look at jaberwockys ImageMagickObject using AutoItObject I wonder if I could use AutoItObject to implement an interface to IExtractImage. To my knowledge implementing specific interfaces in most scripting languages is impossible because they have no support for compile time (early) binding. Certainly it's no problem to implement the methods with the same signature as interface requires but when the client tries something like this: IExtractImage* pEI; HBITBMAP hbm; HRESULT hr = pUnknown->QueryInterface(IIDIExtractImage, &pEI); if (SUCCEEDED(hr)) pEI->Extract(&hbm);it will run into error. There are some exceptions: WSH and MSSOAP help scripting runtimes with special module (XML) files, that describe implemented interfaces, Javascript supports object prototyping (kinda interface declaration). As long as AutoIt misses a comparable feature it is doubtful we would be able to implement external interfaces. UDFS & Apps: Spoiler DDEML.au3 - DDE Client + ServerLocalization.au3 - localize your scriptsTLI.au3 - type information on COM objects (TLBINF emulation)TLBAutoEnum.au3 - auto-import of COM constants (enums)AU3Automation - export AU3 scripts via COM interfacesTypeLibInspector - OleView was yesterday Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE Link to comment Share on other sites More sharing options...
KaFu Posted August 5, 2010 Share Posted August 5, 2010 Thanks for the clarification doudou . OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
shEiD Posted August 19, 2010 Share Posted August 19, 2010 First of all, let me apologize in advance for obviously silly to most of you questions, as I'm a total newbie in programming. All my experience consist of only autoit scripting and all my learning is autoit help file, analyzing autoit's includes and other users scripts, that I find on the forums.I loved this little udf: EASY Multidimensional Associative Arrays which enabled me to make my scripts so much more readable (especially to myself). From many random reads over the years on the nets, I gathered that OO programing is very good at making your code manageable and easily readable. That is my main prerogative, as most often what happens to me, is I write a script and use it for couple of months. Then comes the time, that script needs some updating/adjusting and I can't figure heads or tails of it, when I want to do that. I try to comment wholeheartedly, but often enough I wrote the function by using a snippet of code from some udf from the forums, etc. I did understand how it worked when I used/edited it for my script, but a couple of months later, it takes me ages to figure out whats what. Especially, when the script is long and complicated. It becomes such a mess...Anyway, after that little udf made my life in autoit scripting so muych easier, I finally decided to look into AutoItObject UDF. Am I right to assume from the looks of it (I tried to analyse the provided examples), that AutoItObject enables to write SO much easier readable and manageable scripts? I know it's a silly question, but I repeat myself, I haven't got any real programing experience, that's why I'm asking. School was so long ago, it didn't have any computers back then In uni all my experience with computers was ~1-2 weeks of learning how to turn it on (well, it was medical uni, long time ago, so no computer/classes, of course.)Everything I read about about programing says OO is the way to go, pretty much always. I think all the excitement on this thread, kinda supports that statement? From the examples it looks, that the code sometimes gets longer, but way more readable and reusable?Most important question would be: am I silly for even thinking about using AutoItObject, if I have no OO experience, have no idea what DLLs are and how poisonous they are, if you eat them? Please be frank, and tell me to get my head examined, if that's a case. In my defense, I'm a quick study, but from my "no knowledge whatsoever" standpoint, I'm concerned if maybe you need to have at least some "professional" experience in programing and OO to use it?Example:Examining oLinkedList.au3 example which comes with AutoItObject.expandcollapse popup#include "AutoitObject.au3" Func __Element__($data, $NextEl = 0) $obj = DllCall($ghAutoItObjectDLL,"idispatch","CreateAutoItObject") $obj = $obj[0] DllCall($ghAutoItObjectDLL,"none","AddProperty","idispatch",$obj,"wstr","next",'dword', 0, 'ptr', 0) DllCall($ghAutoItObjectDLL,"none","AddProperty","idispatch",$obj,"wstr","data",'dword', 0, 'ptr', 0) $obj.next = $NextEl $obj.data = $data Return $obj EndFunc ;==>__Element__ Func LinkedList() Local $obj = _AutoItObject_Create() _AutoItObject_AddProperty($obj, "first") _AutoItObject_AddProperty($obj, "last") _AutoItObject_AddProperty($obj, "size") _AutoItObject_AddMethod($obj, "count", "_LinkedList_count") _AutoItObject_AddMethod($obj, "add", "_LinkedList_add") _AutoItObject_AddMethod($obj, "at", "_LinkedList_at") _AutoItObject_AddMethod($obj, "remove", "_LinkedList_remove") _AutoItObject_AddEnum($obj, "_LinkedList_EnumNext" ,"_LinkedList_EnumReset") Return $obj EndFunc ;==>LinkedList Func _LinkedList_remove($self, $index) $current = $self.first $previous = 0 Local $i = 0 Do If $i = $index Then If Not IsObj($previous) Then $self.first = $current.Next Else $previous.Next = $current.Next EndIf $self.size = $self.size - 1 Return EndIf $i += 1 $previous = $current $current = $current.Next Until $current.Next = 0 Return SetError(1, 0, 0) EndFunc ;==>_LinkedList_remove Func _LinkedList_add($self, $newdata) Local $iSize = $self.size Local $oLast = $self.last If $iSize = 0 Then $self.first = __Element__($newdata) $self.last = $self.first Else $oLast.Next = __Element__($newdata) $self.last = $oLast.Next EndIf $self.size = $iSize + 1 EndFunc ;==>_LinkedList_add Func _LinkedList_at($self, $index) Local $i = 0 For $Element In $self If $i = $index Then Return $Element $i += 1 Next Return SetError(1, 0, 0) EndFunc ;==>_LinkedList_at Func _LinkedList_count($self) Return $self.size EndFunc ;==>_LinkedList_count Func _LinkedList_EnumReset(ByRef $self, ByRef $iterator) $iterator = 0 EndFunc ;==>_LinkedList_EnumReset Func _LinkedList_EnumNext(ByRef $self, ByRef $iterator) If Not IsObj($iterator) Then $iterator = $self.first Return $iterator.data EndIf If Not IsObj($iterator.Next) Then Return SetError(1, 0, 0) $iterator = $iterator.Next Return $iterator.data EndFunc ;==>_LinkedList_EnumNext ;~ #CS Uncomment to run example! _AutoItObject_Startup() $ll = LinkedList() For $i = 1 To 10 $ll.add($i) Next $ll.remove(4) $str = "" For $e In $ll $str &= $e & @CRLF Next MsgBox(0, $ll.count, $str) ;~ #CEDo I understand correctly?Object properties are as variables in autoit, they have values and can be "neatly" accessed by using oObj.PropertyObject methods are functions, which can be called in the same neat manner (I love this part) as oObj.MethodYou create an object once and can copy it with all the properties and methodsSpecific questions, that puzzle me:In the oLinkedList.au3 example I don't see .next or .data methods (these are methods, right?) defined. Are they from some sort of "in-built" methods? Where can I find a list/documentation of them and their usage (I couldn't find it in AutoItObject.chm)?Property obj.size is always set in $obj.add method, so why create obj.count (_LinkedList_count() function) which simply returns obj.size? Can't I simply always use obj.size to get the value? Confusing...Object methods are functions with 2 parameters (_LinkedList_remove($self, $index)), but when you call the method, you call it with just 1 parameter, and the first parameter is ommited. I'm I understanding right, that the first parameter of the function, which defines the method is always $self, that is the object itself?Thanks in advance. And for anyone who had the patience to read through all of it, sorry for such a long post. Link to comment Share on other sites More sharing options...
shEiD Posted August 19, 2010 Share Posted August 19, 2010 (edited) I found a bug in oLinkedList.au3 example - the .remove method did not remove the last element:Func _LinkedList_remove($self, $index) $current = $self.first $previous = 0 Local $i = 0 Do If $i = $index Then If Not IsObj($previous) Then $self.first = $current.Next Else $previous.Next = $current.Next EndIf $self.size = $self.size - 1 Return EndIf $i += 1 $previous = $current $current = $current.Next ;Until $current.Next = 0 ; <--- change this line Until $i = $self.size ; <--- into this Return SetError(1, 0, 0) EndFunc ;==>_LinkedList_removeIt was confusing, coz Return SetError(1, 0, 0) was not passed on, and error check did not alarm me of the error. Question: is this a normal behavior, that when you call an objec'ts method, the error that function sets gets reset somewhere until method call returns? I mean, should I let's say, create additional parameter for an object $obj.LastError and set the error code to that property, to be able to check for it after method call returns? Edited August 19, 2010 by shEiD Link to comment Share on other sites More sharing options...
trancexx Posted August 19, 2010 Share Posted August 19, 2010 (edited) I found a bug in oLinkedList.au3 example - the .remove method did not remove the last element: Func _LinkedList_remove($self, $index) $current = $self.first $previous = 0 Local $i = 0 Do If $i = $index Then If Not IsObj($previous) Then $self.first = $current.Next Else $previous.Next = $current.Next EndIf $self.size = $self.size - 1 Return EndIf $i += 1 $previous = $current $current = $current.Next ;Until $current.Next = 0 ; <--- change this line Until $i = $oSelf.size ; <--- into this Return SetError(1, 0, 0) EndFunc ;==>_LinkedList_remove It was confusing, coz Return SetError(1, 0, 0) was not passed on, and error check did not alarm me of the error. Question: is this a normal behavior, that when you call an objec'ts method, the error that function sets gets reset somewhere until method call returns? I mean, should I let's say, create additional parameter for an object $obj.LastError and set the error code to that property, to be able to check for it after method call returns? You have __error__ property at disposal by default. Modified example :_AutoItObject_Startup() $ll = LinkedList() For $i = 1 To 10 $ll.add($i) Next $ll.remove(123) ;<- 123 is out of range (anything above 9 in this case) ConsoleWrite("!error = " & $ll.__error__ & @CRLF) $str = "" For $e In $ll $str &= $e & @CRLF Next MsgBox(0, $ll.count, $str) Btw, thanks. edit: eng Edited August 19, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
wraithdu Posted August 19, 2010 Share Posted August 19, 2010 (edited) You can simplify it a bit as 'Until $current = 0' But yeah, I see that @error is lost somewhere as well. Edit: I see your reply now. @trancexxx Is there a similar way to access @extended? Edited August 19, 2010 by wraithdu Link to comment Share on other sites More sharing options...
trancexx Posted August 19, 2010 Share Posted August 19, 2010 Object methods are functions with 2 parameters (_LinkedList_remove($self, $index)), but when you call the method, you call it with just 1 parameter, and the first parameter is ommited. I'm I understanding right, that the first parameter of the function, which defines the method is always $self, that is the object itself?Yes. This was monoceres's choice. It could have been implemented differently. To resemble some other languages he uses, I suppose. Semantics.@wraithduuNo. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
shEiD Posted August 19, 2010 Share Posted August 19, 2010 (edited) Something really confusing: using the same oLinkedList.au3 example (btw, loving it and using it extensively, thank You so much):If I use the linked list to store objects and then delete the linked list, for some reason the destructor for (once again) last element does not get triggered... #include "AutoitObject.au3" #include "oLinkedList.au3" If $ghAutoItObjectDLL < 0 Then _AutoItObject_StartUp() $ll = LinkedList() For $i = 1 To 10 $obj = Test() Sleep(100) $obj.Name = 'test object ' & $i ConsoleWrite('-(' & @ScriptLineNumber & ')' & @TAB & 'object (' & $obj.Name & ') added' & @CRLF) $ll.add($obj) Next $ll = 0 Exit Func Test() Local $oClassObject = _AutoItObject_Class() $oClassObject.Create() $oClassObject.AddProperty("Name") $oClassObject.AddDestructor("__Test__Destructor") Return $oClassObject.Object EndFunc ;==>Test Func __Test__Destructor($oSelf) ConsoleWrite('!(' & @ScriptLineNumber & ')' & @TAB & 'destructing object(' & $oSelf.Name & ')' & @CRLF) EndFunc ;==>__Test__DestructorPS, @trancexx, thanks for the answers. Edited August 19, 2010 by shEiD Link to comment Share on other sites More sharing options...
trancexx Posted August 21, 2010 Share Posted August 21, 2010 Something really confusing: using the same oLinkedList.au3 example (btw, loving it and using it extensively, thank You so much): If I use the linked list to store objects and then delete the linked list, for some reason the destructor for (once again) last element does not get triggered... #include "AutoitObject.au3" #include "oLinkedList.au3" If $ghAutoItObjectDLL < 0 Then _AutoItObject_StartUp() $ll = LinkedList() For $i = 1 To 10 $obj = Test() Sleep(100) $obj.Name = 'test object ' & $i ConsoleWrite('-(' & @ScriptLineNumber & ')' & @TAB & 'object (' & $obj.Name & ') added' & @CRLF) $ll.add($obj) Next $ll = 0 Exit Func Test() Local $oClassObject = _AutoItObject_Class() $oClassObject.Create() $oClassObject.AddProperty("Name") $oClassObject.AddDestructor("__Test__Destructor") Return $oClassObject.Object EndFunc ;==>Test Func __Test__Destructor($oSelf) ConsoleWrite('!(' & @ScriptLineNumber & ')' & @TAB & 'destructing object(' & $oSelf.Name & ')' & @CRLF) EndFunc ;==>__Test__Destructor PS, @trancexx, thanks for the answers. Try this as _LinkedList_Remove: Func _LinkedList_Remove($oSelf, $iIndex) Local $iSize = $oSelf.size If $iIndex >= $iSize Then Return SetError(1, 0, False) Local $oCurrent = $oSelf.first Local $oPrevious #forceref $oPrevious For $i = 0 To $iSize - 1 If $i = $iIndex Then If $i = $iSize - 1 Then If $iSize = 1 Then Return SetError(-1, 0, False) ;<- ! special case If IsObj($oSelf.at($i)) Then SetError(-2) ;<- ! another special case EndIf $oPrevious.next = $oCurrent.next ExitLoop EndIf $oPrevious = $oCurrent $oCurrent = $oCurrent.next Next $oSelf.size = $oSelf.size - 1 Return True EndFunc It deals wit all special cases that could occur and should be faster. By using that function you can check __error__ property and see what happens when you try to remove members. As for not releasing last objects. That's like cyclic reference issue. You need to add Release method for your objects. #include "AutoitObject.au3" #include "oLinkedList.au3" _AutoItObject_StartUp() $ll = LinkedList() For $i = 1 To 10 $obj = Test() Sleep(100) $obj.Name = 'test object ' & $i ConsoleWrite('-(' & @ScriptLineNumber & ')' & @TAB & 'object (' & $obj.Name & ') added' & @CRLF) $ll.add($obj) Next $olast = $ll.at($ll.size - 1) $olast.Release() $ll = 0 Exit Func Test() Local $oClassObject = _AutoItObject_Class() $oClassObject.Create() $oClassObject.AddProperty("Name") $oClassObject.AddDestructor("__Test__Destructor") $oClassObject.AddMethod("Release", "__Test__Destructor") Return $oClassObject.Object EndFunc ;==>Test Func __Test__Destructor($oSelf) ConsoleWrite('!(' & @ScriptLineNumber & ')' & @TAB & 'destructing object(' & $oSelf.Name & ')' & @CRLF) EndFunc ;==>__Test__Destructor Somebody will rewrite oLinkedList.au3 for the new release whenever that be. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
wraithdu Posted August 21, 2010 Share Posted August 21, 2010 (edited) I won't pretend that I work with linked lists with any regularity, but is there a reason you don't remove the last element in the list (size = 1)? Can't you just set size, first, and last to 0? Func _LinkedList_Remove($oSelf, $iIndex) Local $iSize = $oSelf.size If $iSize = 0 Then Return SetError(1, 0, False) If $iIndex >= $iSize Then Return SetError(2, 0, False) Local $oCurrent = $oSelf.first Local $oPrevious #forceref $oPrevious For $i = 0 To $iSize - 1 If $i = $iIndex Then If $i = $iSize - 1 Then If IsObj($oSelf.at($i)) Then SetError(-1) ;<- ! another special case If $iSize = 1 Then ;Return SetError(-1, 0, False) ;<- ! special case $oSelf.first = 0 $oSelf.last = 0 ExitLoop EndIf EndIf $oPrevious.Next = $oCurrent.Next ExitLoop EndIf $oPrevious = $oCurrent $oCurrent = $oCurrent.Next Next $oSelf.size = $oSelf.size - 1 Return True EndFunc ;==>_LinkedList_Remove Edited August 21, 2010 by wraithdu Link to comment Share on other sites More sharing options...
wraithdu Posted August 21, 2010 Share Posted August 21, 2010 I've found a bug in _AutoItObject_AddProperty. You use the @NumParams macro to test for setting data in vData. However if vData is not explicitly passed to the function, then the default value of 0 is ignored, and vData = "". So, maybe not a bug as much as an error in the documentation / function header. Also, _LinkedList_EnumNext should test if $iterator is an object after '$iterator = $self.first'. Currently, if you use 'For $ea in $ll' before adding an element to the list, you get an infinite loop. Or just test the $self.size <> 0, yeah, that's probably easier. Link to comment Share on other sites More sharing options...
trancexx Posted August 21, 2010 Share Posted August 21, 2010 I won't pretend that I work with linked lists with any regularity, but is there a reason you don't remove the last element in the list (size = 1)? Can't you just set size, first, and last to 0? Func _LinkedList_Remove($oSelf, $iIndex) Local $iSize = $oSelf.size If $iIndex >= $iSize Then Return SetError(1, 0, False) Local $oCurrent = $oSelf.first Local $oPrevious #forceref $oPrevious For $i = 0 To $iSize - 1 If $i = $iIndex Then If $i = $iSize - 1 Then If IsObj($oSelf.at($i)) Then SetError(-1) ;<- ! another special case If $iSize = 1 Then ;Return SetError(-1, 0, False) ;<- ! special case $oSelf.first = 0 $oSelf.last = 0 ExitLoop EndIf EndIf $oPrevious.Next = $oCurrent.Next ExitLoop EndIf $oPrevious = $oCurrent $oCurrent = $oCurrent.Next Next $oSelf.size = $oSelf.size - 1 Return True EndFunc ;==>_LinkedList_Remove Are you removing it? Or replacing it? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
wraithdu Posted August 21, 2010 Share Posted August 21, 2010 (edited) $oSelf.size is reduced to 0, so it is effectively removed. The test in the _Add function is 'If $iSize = 0'. $oSelf.first and .last set to 0 also removes it as they are not objects any more. Adding 'If $self.size = 0 Then Return SetError(1, 0, 0)' to the first line of the _EnumNext fixes any other issues. See above again for an edit to the _Remove function that also tests $iSize = 0. Edited August 21, 2010 by wraithdu Link to comment Share on other sites More sharing options...
trancexx Posted August 21, 2010 Share Posted August 21, 2010 $oSelf.size is reduced to 0, so it is effectively removed. The test in the _Add function is 'If $iSize = 0'. $oSelf.first and .last set to 0 also removes it as they are not objects any more. Adding 'If $self.size = 0 Then Return SetError(1, 0, 0)' to the first line of the _EnumNext fixes any other issues. See above again for an edit to the _Remove function that also tests $iSize = 0.Other functions should probably be rethinked. I wish monoceres shows up eventually, this is his area.Could you go thru the rest of that UDF? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
wraithdu Posted August 21, 2010 Share Posted August 21, 2010 (edited) I think this should work correctly. Another set of eyes please? EDIT Wait, more edits coming... Ok, now take a look. expandcollapse popup#include-once #include <AutoItObject.au3> Func __Element__($data, $NextEl = 0) Local $obj = DllCall($ghAutoItObjectDLL, "idispatch", "CreateAutoItObject") $obj = $obj[0] DllCall($ghAutoItObjectDLL, "none", "AddProperty", "idispatch", $obj, "wstr", "Next", 'dword', 0, 'ptr', 0) DllCall($ghAutoItObjectDLL, "none", "AddProperty", "idispatch", $obj, "wstr", "data", 'dword', 0, 'ptr', 0) $obj.next = $NextEl $obj.data = $data Return $obj EndFunc ;==>__Element__ Func LinkedList() Local $obj = _AutoItObject_Create() _AutoItObject_AddProperty($obj, "first", $ELSCOPE_PUBLIC, 0) _AutoItObject_AddProperty($obj, "last", $ELSCOPE_PUBLIC, 0) _AutoItObject_AddProperty($obj, "size", $ELSCOPE_PUBLIC, 0) _AutoItObject_AddMethod($obj, "count", "_LinkedList_count") _AutoItObject_AddMethod($obj, "add", "_LinkedList_add") _AutoItObject_AddMethod($obj, "at", "_LinkedList_at") _AutoItObject_AddMethod($obj, "remove", "_LinkedList_remove") _AutoItObject_AddEnum($obj, "_LinkedList_EnumNext", "_LinkedList_EnumReset") Return $obj EndFunc ;==>LinkedList Func _LinkedList_remove($self, $index) If $self.size = 0 Then Return SetError(1, 0, 0) Local $current = $self.first Local $previous = 0 Local $i = 0 Do If $i = $index Then If $self.size = 1 Then ; very last element $self.first = 0 $self.last = 0 ElseIf $i = 0 Then ; first element $self.first = $current.next Else If $i = $self.size - 1 Then $self.last = $previous ; last element $previous.next = $current.next EndIf $self.size = $self.size - 1 Return EndIf $i += 1 $previous = $current $current = $current.next Until $current = 0 Return SetError(2, 0, 0) EndFunc ;==>_LinkedList_remove Func _LinkedList_add($self, $newdata) Local $iSize = $self.size Local $oLast = $self.last If $iSize = 0 Then $self.first = __Element__($newdata) $self.last = $self.first Else $oLast.next = __Element__($newdata) $self.last = $oLast.next EndIf $self.size = $iSize + 1 EndFunc ;==>_LinkedList_add Func _LinkedList_at($self, $index) Local $i = 0 For $Element In $self If $i = $index Then Return $Element $i += 1 Next Return SetError(1, 0, 0) EndFunc ;==>_LinkedList_at Func _LinkedList_count($self) Return $self.size EndFunc ;==>_LinkedList_count Func _LinkedList_EnumReset(ByRef $self, ByRef $iterator) #forceref $self $iterator = 0 EndFunc ;==>_LinkedList_EnumReset Func _LinkedList_EnumNext(ByRef $self, ByRef $iterator) If $self.size = 0 Then Return SetError(1, 0, 0) If Not IsObj($iterator) Then $iterator = $self.first Return $iterator.data EndIf If Not IsObj($iterator.next) Then Return SetError(1, 0, 0) $iterator = $iterator.next Return $iterator.data EndFunc ;==>_LinkedList_EnumNext Edited August 21, 2010 by wraithdu Link to comment Share on other sites More sharing options...
wraithdu Posted August 21, 2010 Share Posted August 21, 2010 (edited) I also figured out shEiD's problem. It's not that you need a release method, it's that his/her example still had a lingering reference to the last object. This works fine: _AutoItObject_Startup() $ll = LinkedList() For $i = 1 To 10 $obj = Test() $obj.Name = 'test object ' & $i ConsoleWrite('-(' & @ScriptLineNumber & ')' & @TAB & 'object (' & $obj.Name & ') added' & @CRLF) $ll.add($obj) Next ; this is the problem with global variables ; make sure to release this reference to the last object! $obj = 0 $ll = 0 Exit Func Test() Local $oClassObject = _AutoItObject_Class() $oClassObject.Create() $oClassObject.AddProperty("Name") $oClassObject.AddDestructor("__Test__Destructor") Return $oClassObject.Object EndFunc ;==>Test Func __Test__Destructor($oSelf) ConsoleWrite('!(' & @ScriptLineNumber & ')' & @TAB & 'destructing object(' & $oSelf.Name & ')' & @CRLF) EndFunc ;==>__Test__Destructor Edited August 21, 2010 by wraithdu Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now