home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / CanDo / Decks1 / CanDoV2 / Tutorial2.ctx < prev    next >
Encoding:
Text File  |  1998-07-25  |  7.4 KB  |  304 lines

  1. *************
  2. * Deck "TestDrive2"
  3. *************
  4.  
  5. *************
  6. * Card(s) in deck.
  7. *  Card "CARD#1"
  8. *************
  9. * 1 Card(s), 1 were printed.
  10. *************
  11.  
  12. *************
  13. * Natural order of Cards
  14. *  Card "CARD#1"
  15. *************
  16.  
  17. *************
  18. * Global Routine(s) in deck.
  19. *  Routine "Add Entry"
  20. *  Routine "Delete Entry"
  21. *  Routine "Display Entry"
  22. *  Routine "Load Database"
  23. *  Routine "Next Entry"
  24. *  Routine "Previous Entry"
  25. *  Routine "Save Database"
  26. *  Routine "Search For Entry"
  27. *  Routine "Sort DataBase"
  28. *************
  29. * 9 Global routines(s), 9 were printed.
  30. *************
  31.  
  32. *************
  33. * Card "CARD#1"
  34.     AfterAttachment
  35.         Let DataFile = "TestDB.DAT"
  36.         Do "Load Database"
  37.     EndScript
  38.     PictureWindow "UserWindow"
  39.         Definition
  40.             Origin 0,0
  41.             BackgroundImage "CanDo:Images/MovieBackdrop.ilbm" ; size and depth comes from image
  42.             Title ""
  43.             DefaultColors 0,1,0
  44.             WindowObjects CLOSEBUTTON DEPTHBUTTONS DRAGBAR 
  45.             WindowFlags ACTIVATE SEPARATESCREEN TOFRONT 
  46.             VisualEffects NONE ,WAIT 
  47.         EndScript
  48.         OnCloseButton
  49.             Quit
  50.         EndScript
  51.     EndObject
  52.     AltImageButton "Previous Button"
  53.         Definition
  54.             Origin 15,50
  55.             Image "CanDo:Brushes/left1.grab"
  56.             AltImage "CanDo:Brushes/left2.grab"
  57.             Shape "CanDo:Brushes/left1.grab"
  58.             ButtonFlags NONE 
  59.         EndScript
  60.         OnRelease
  61.             Do "Previous Entry"
  62.         EndScript
  63.     EndObject
  64.     AltImageButton "Next Button"
  65.         Definition
  66.             Origin 60,50
  67.             Image "CanDo:Brushes/right1.grab"
  68.             AltImage "CanDo:Brushes/right2.grab"
  69.             Shape "CanDo:Brushes/right1.grab"
  70.             ButtonFlags NONE 
  71.         EndScript
  72.         OnRelease
  73.             Do "Next Entry"
  74.         EndScript
  75.     EndObject
  76.     TextButton "Add Button"
  77.         Definition
  78.             Origin 20,75
  79.             Font "topaz",8 ; FontName, PointSize
  80.             Style SHADOW ,2,3
  81.             TextColors 3,0,JAM1  ; PenA, PenB, DrawMode
  82.             Text "  Add  "
  83.             Border SHADOW ,1,2 ; BorderStyle, MainPen, ExtraPen
  84.             Highlight COMPLEMENT 
  85.             ButtonFlags NONE 
  86.         EndScript
  87.         OnRelease
  88.             Do "Add Entry"
  89.         EndScript
  90.     EndObject
  91.     TextField ".Name"
  92.         Definition
  93.             Origin 230,52
  94.             Size 320,8
  95.             Justification LEFT 
  96.             MaxFieldLength 40
  97.             InitialText ""
  98.             Border DOUBLEBEVEL ,1,2 ; BorderStyle, MainPen, ExtraPen
  99.         EndScript
  100.     EndObject
  101.     IntegerField ".Number"
  102.         Definition
  103.             Origin 230,70
  104.             Size 80,8
  105.             Justification LEFT 
  106.             MaxFieldLength 10
  107.             Limits 0,2147483647
  108.             InitialInteger 0
  109.             Border DOUBLEBEVEL ,1,2 ; BorderStyle, MainPen, ExtraPen
  110.         EndScript
  111.     EndObject
  112.     Memo ".Description"
  113.         Definition
  114.             Origin 230,88
  115.             Size 320,64
  116.             Font "topaz",8 ; FontName, PointSize
  117.             Style PLAIN ,2,3
  118.             TextColors 1,0,JAM2  ; PenA, PenB, DrawMode
  119.             Border DOUBLEBEVEL ,1,2 ; BorderStyle, MainPen, ExtraPen
  120.             MemoDocument "Description - Doc" ; where the text comes from
  121.             ScrollBars RIGHT 
  122.             InputStyle NORMAL 
  123.         EndScript
  124.     EndObject
  125.     TextField "SearchField"
  126.         Definition
  127.             Origin 230,165
  128.             Size 320,8
  129.             Justification LEFT 
  130.             MaxFieldLength 40
  131.             InitialText ""
  132.             Border OUTLINE ,1,2 ; BorderStyle, MainPen, ExtraPen
  133.         EndScript
  134.         OnRelease
  135.             Do "Search For Entry",TextFrom("SearchField"),".Name"
  136.             SetObjectState "SearchField",ON
  137.         EndScript
  138.     EndObject
  139.     TextMenu "Save"
  140.         Definition
  141.             AttachTo MENU ,"Project"
  142.             Font "topaz",8 ; FontName, PointSize
  143.             Style PLAIN ,2,3
  144.             TextColors 0,1,JAM1  ; PenA, PenB, DrawMode
  145.             Text "Save"
  146.             MenuFlags NONE 
  147.             Highlight COMPLEMENT 
  148.             ShortCutKey "S"
  149.         EndScript
  150.         Occurred
  151.             Do "Save Database"
  152.         EndScript
  153.     EndObject
  154.     TextMenu "Load"
  155.         Definition
  156.             AttachTo MENU ,"Project"
  157.             Font "topaz",8 ; FontName, PointSize
  158.             Style PLAIN ,2,3
  159.             TextColors 0,1,JAM1  ; PenA, PenB, DrawMode
  160.             Text "Load"
  161.             MenuFlags NONE 
  162.             Highlight COMPLEMENT 
  163.             ShortCutKey "L"
  164.         EndScript
  165.         Occurred
  166.             Do "Load Database"
  167.         EndScript
  168.     EndObject
  169.     TextMenu "Sort"
  170.         Definition
  171.             AttachTo MENU ,"Options"
  172.             Font "topaz",8 ; FontName, PointSize
  173.             Style PLAIN ,2,3
  174.             TextColors 0,1,JAM1  ; PenA, PenB, DrawMode
  175.             Text "Sort"
  176.             MenuFlags NONE 
  177.             Highlight COMPLEMENT 
  178.             ShortCutKey ""
  179.         EndScript
  180.         Occurred
  181.             Do "Sort DataBase",".Name"
  182.         EndScript
  183.     EndObject
  184.     TextMenu "Delete"
  185.         Definition
  186.             AttachTo MENU ,"Options"
  187.             Font "topaz",8 ; FontName, PointSize
  188.             Style PLAIN ,2,3
  189.             TextColors 0,1,JAM1  ; PenA, PenB, DrawMode
  190.             Text "Delete"
  191.             MenuFlags NONE 
  192.             Highlight COMPLEMENT 
  193.             ShortCutKey ""
  194.         EndScript
  195.         Occurred
  196.             Do "Delete Entry"
  197.         EndScript
  198.     EndObject
  199. * End of Card "CARD#1"
  200. *************
  201.  
  202. *************
  203. * Global routine "Add Entry"
  204.     Let DataBase[Index] = GetDBOBjects    ; save current entry
  205.     Let Index = Index + 1                ; insert it at next index
  206.     InsertArrayEntry DataBase,Index        ; make space for it
  207.     Do "Display Entry"
  208. * End of routine "Add Entry"
  209. *************
  210.  
  211. *************
  212. * Global routine "Delete Entry"
  213.     DeleteArrayEntry DataBase,Index            ; delete this dude
  214.     If VarType(DataBase[Index]) = "Nothing"    ; check if last(end) entry
  215.         Let Index = LastArrayIndex(DataBase); find new last(end) entry
  216.     EndIf
  217.     Do "Display Entry"
  218. * End of routine "Delete Entry"
  219. *************
  220.  
  221. *************
  222. * Global routine "Display Entry"
  223.     SetDBObjects DataBase[Index]                ; display Entry
  224.     SetWindowTitle "Entry #" || Index
  225. * End of routine "Display Entry"
  226. *************
  227.  
  228. *************
  229. * Global routine "Load Database"
  230.     Dispose DataBase                            ; get rid of current
  231.     If Exists(DataFile)                            ; check if file exists
  232.         Let DataBase = LoadVariable(DataFile)    ; load it
  233.         IfError    ;this simple example does nothing for an error
  234.         EndIf    ;you can do something like display a requester
  235.     EndIf
  236.     Let Index = FirstArrayIndex(DataBase)        ; go to first entry
  237.     Do "Display Entry"
  238. * End of routine "Load Database"
  239. *************
  240.  
  241. *************
  242. * Global routine "Next Entry"
  243.     Let DataBase[Index] = GetDBOBjects            ; Save Entry
  244.     Let Index = NextArrayIndex(DataBase,Index)    ; Look for Next entry
  245.     If Not SearchFound                            ; Check if at end
  246.         Let Index = FirstArrayIndex(DataBase)    ; go to first one
  247.     EndIf
  248.     Do "Display Entry"
  249. * End of routine "Next Entry"
  250. *************
  251.  
  252. *************
  253. * Global routine "Previous Entry"
  254.     Let DataBase[Index] = GetDBOBjects                ; save entry
  255.     Let Index = PreviousArrayIndex(DataBase,Index)    ; find previous
  256.     If Not SearchFound                                ; if not one
  257.         Let Index = LastArrayIndex(DataBase)        ; go to last one
  258.     EndIf
  259.     Do "Display Entry"
  260. * End of routine "Previous Entry"
  261. *************
  262.  
  263. *************
  264. * Global routine "Save Database"
  265.     Let DataBase[Index] = GetDBObjects        ; save current entry
  266.     SaveVariable DataBase,DataFile            ; save it
  267.     IfError ;this simple example does not do anything for an error
  268.     EndIf    ;however, you can do something like display a requester
  269. * End of routine "Save Database"
  270. *************
  271.  
  272. *************
  273. * Global routine "Search For Entry"
  274.     Nop; ARG1 = "Search Value"
  275.     Nop; ARG2 = "Search Key"
  276.     Nop; example - Do "Search For Entry","Henry",".Name"
  277.     Nop
  278.     Let DataBase[Index] = GetDBOBjects            ; Save Entry
  279.     SetSearchArrayFlags NOCASE SUBSTRING 
  280.     Let OldIndex = Index ;save index in case Arg1 is not found
  281.     Let Index = SearchArray(DataBase,Arg1,Arg2,Index+1)    ; search from next index
  282.     If Not SearchFound                            ; Check if found it
  283.         Let Index = SearchArray(DataBase,Arg1,Arg2)    ; search from beginning
  284.         If Not SearchFound
  285.             Let Index = OldIndex    ;not found - goto original index
  286.         EndIf
  287.     EndIf
  288.     Do "Display Entry" ; Display it!
  289. * End of routine "Search For Entry"
  290. *************
  291.  
  292. *************
  293. * Global routine "Sort DataBase"
  294.     Nop ; ARG1 = "Sort key"
  295.     Nop ; example - Do "Sort DataBase",".Name"
  296.     Nop
  297.     Let DataBase[Index] = GetDBOBjects        ; Save Entry
  298.     SortArray DataBase,NOCASE STRING ,ARG1    ; Sort Data
  299.     Let Index = FirstArrayIndex(DataBase)    ; go to first one
  300.     Do "Display Entry"
  301. * End of routine "Sort DataBase"
  302. *************
  303.  
  304.