Page 1 of 1

Posted: Sun Nov 10, 2002 7:52 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.

I have the code below and it all works fine with one exception. The designated TextGadget does not show the text I am shoving at it with SetGadgetText. The hourglass appears over the gadget indicating that it is busy but that is it.

Is it possible that the gadget cannot update that fast??

Code: Select all

Structure record
  deleted.l
  marked.l
  diskfile.b[255]
  filesize.b[14]
  version.b[6]
  crc32.b[15]
  filename.b[50]
  filetype.b[15]
  category.b[30]
  collection.b[30]
  display.b[30]
  trademark.b[30]
  tradelink.b[50]
  comments.b[255]
EndStructure

Structure dbheader
  numrecords.l
  numdeleted.l
  recordlen.l
EndStructure

NewList dir.s()

#database = "IncrediMailStyles.dat"

#displaybox = 1
#gobutton = 2

; Setup global strings so we don't have to constantly pass long winded parameters -------

Global diskfile.s, filesize.s, version.s, crc32.s
Global filename.s, filetype.s, category.s, collection.s, display.s, trademark.s, tradelink.s, comments.s
Global recbuf.record, header.dbheader

;- precalculated variables --------------------------------------------------------------

header\recordlen = SizeOf(record)

;- Open the database or create it if it doesn't exist -----------------------------------

If FileSize(#database) > 0
  OpenFile(1, #database)
  ReadData(@header, SizeOf(dbheader))
  CloseFile(1)
Else
  CreateFile(1, #database)
  WriteData(@header, SizeOf(dbheader))
  CloseFile(1)
EndIf
; ---------------------------------------------------------------------------------------

Declare$ getini(key$, section$)                           ; Declare any needed routines
Declare$ fillcontent(content$)

;----------------------------------------------------------------------------------------

Procedure$ getini(key$, section$)                         ; API procedure to replace Mr Skunk's INI file reading routine
  empty$ = "Empty"
  returnspace$ = Space(255)
  inidata = GetPrivateProfileString_(section$, key$, empty$, @returnspace$, 255, "C:\iCat2\content.ini")
  ProcedureReturn returnspace$
EndProcedure

;- Main code starts here ----------------------------------------------------------------

  fontname$ = "Comic Sans MS"
  fontheight = 10
  font = LoadFont(1, fontname$, fontheight)
  SetGadgetFont(font)
  ;--------------------------------------------------------------------------------------
  winx = (GetSystemMetrics_(#SM_CXSCREEN) - 630) / 2
  winy = (GetSystemMetrics_(#SM_CYSCREEN) - 40) / 2

  mainwindow = OpenWindow(0, Random(winx), Random(winy), 630, 40, #PB_Window_SystemMenu, "")
  
  If mainwindow = 0 Or CreateGadgetList(WindowID()) = 0
    End
  EndIf

  StringGadget(#displaybox, 5, 5, 500, 25, "")
  ButtonGadget(#gobutton, 505, 5, 100, 25, "Go")
  ;--------------------------------------------------------------------------------------
  Repeat

    eventid = WaitWindowEvent()

    If eventid = #PB_EventCloseWindow
      quitvalue = 1
    EndIf
    ;----------------------------------------------
    If eventid = #PB_EventGadget
      Select EventGadgetID()
        Case #gobutton  : Gosub maincode
      EndSelect
    EndIf
  
  Until quitvalue = 1
  
  CloseWindow(0)
  
  End
  
;----------------------------------------------------------------------------------------
; Main code for getting files
;----------------------------------------------------------------------------------------

maincode:

  AddElement(dir())
  dir() = PathRequester("Select the drive And directory To catalogue", "")
  idx = 0
  Repeat
  SelectElement(dir(), idx)
  If ExamineDirectory(0, dir(), "*.*")
    path.s = dir() + "\"
    quit = 0
    Repeat
      nextfile = NextDirectoryEntry()
      filename.s = DirectoryEntryName()
      Select nextfile
        Case 0
          quit = 1
        Case 1
          count + 1
          ;------------------------------------------------------------------------------
          itype.s = Right(filename, 4)
          Select itype.s
            Case ".ima"
              diskfile = path + filename
              SetGadgetText(#displaybox, diskfile)
              Gosub processcurrentfile
            Case ".imf" 
              diskfile = path + filename
              SetGadgetText(#displaybox, diskfile)
              Gosub processcurrentfile
            Case ".ime"
              diskfile = path + filename
              SetGadgetText(#displaybox, diskfile)
              Gosub processcurrentfile
            Case ".imi"
              diskfile = path + filename
              SetGadgetText(#displaybox, diskfile)
              Gosub processcurrentfile
            Case ".imf"
              diskfile = path + filename
              SetGadgetText(#displaybox, diskfile)
              Gosub processcurrentfile
            Case ".imn"
              diskfile = path + filename
              SetGadgetText(#displaybox, diskfile)
              Gosub processcurrentfile
            Case ".ims"
              diskfile = path + filename
              SetGadgetText(#displaybox, diskfile)
              Gosub processcurrentfile
            Case ".imw"
              diskfile = path + filename
              SetGadgetText(#displaybox, diskfile)
              Gosub processcurrentfile
          EndSelect
          ;------------------------------------------------------------------------------
        Case 2
          filename.s = DirectoryEntryName()
          If filename  ".." And filename  "."
            AddElement(dir())
            dir() = path + filename
          EndIf
      EndSelect  
    Until quit = 1
  EndIf
  idx + 1
  Until idx > CountList(dir())

Return

;----------------------------------------------------------------------------------------
; Process the files found during the directory search
;----------------------------------------------------------------------------------------

processcurrentfile:

  filesize = Str(FileSize(diskfile) / 1024) + "k"           ; Get the disk filename size
  ;--------------------------------------------------------------------------------------
  If ReadFile(0, diskfile)                                  ; Get the 32 bit crc if you can read it
    length = Lof()
    buffer = AllocateMemory(0, length)
    ReadData(buffer,length)
    crc32 = Hex(CRC32Fingerprint(buffer, length))
  EndIf
  FreeMemory(0) 
  ;--------------------------------------------------------------------------------------
  unpacker$ = "C:\iCat2\extract.exe"                        ; Drive and directory for extract.exe
            
  params$ = " /Y /E /L C:\iCat2\ " + Chr(34) + diskfile + Chr(34) + " content.ini" ; Make unpack String

  If RunProgram(unpacker$, params$, "", 1 | 2)  0
  EndIf
  ;--------------------------------------------------------------------------------------
  section$ = "Version"
    version = getini("Number", section$)
  section$ = "General"
    filename = getini("File", section$)
    filetype = getini("Type", section$)
    category = getini("Category", section$)
    collection = getini("Collection", section$)
    display = getini("Display", section$)
  section$ = "Trademark"
    trademark = getini("TradeMark", section$)
  section$ = "X-Extensions"
    tradelink = getini("TradeMarkLink", section$)
  ;--------------------------------------------------------------------------------------
  For r = 0 To SizeOf(record) - 1                                ; Must start at 0 and end at record - 1
    PokeB(@recbuf\deleted + r, 0)                                 ; Poke 0's at position (r)
  Next r
  ;--------------------------------------------------------------------------------------
  recbuf\deleted = 0
  recbuf\marked = 0

  CopyMemory(@diskfile, @recbuf\diskfile[0], Len(diskfile))
  CopyMemory(@filesize, @recbuf\filesize[0], Len(filesize))
  CopyMemory(@version, @recbuf\version[0], Len(version))
  CopyMemory(@crc32, @recbuf\crc32[0], Len(crc32))
  CopyMemory(@filename, @recbuf\filename[0], Len(filename))
  CopyMemory(@filetype, @recbuf\filetype[0], Len(filetype))
  CopyMemory(@category, @recbuf\category[0], Len(category))
  CopyMemory(@collection, @recbuf\collection[0], Len(collection))
  CopyMemory(@display, @recbuf\display[0], Len(display))
  CopyMemory(@trademark, @recbuf\trademark[0], Len(trademark))
  CopyMemory(@tradelink, @recbuf\tradelink[0], Len(tradelink))
  comments = " ": CopyMemory(@comments, @recbuf\comments[0], Len(comments))
  ;--------------------------------------------------------------------------------------

  If OpenFile(1, #database)
    
    FileSeek(Lof())                                                 ; Seek to the end of the file
    WriteData(@recbuf, SizeOf(record))                              ; Write the record to disk

    header\recordlen = SizeOf(record)                               ; Compute the length of the record
    header\numrecords + 1                                           ; Calculate new number of records
            
    FileSeek(0)                                                     ; Seek to the start of the file
           
    WriteData(@header, SizeOf(dbheader))                            ; Write the header details (file length, records)
            
    CloseFile(1)                                                    ; Close the file
    ;------------------------------------------------------------------------------------
    For r = 0 To SizeOf(record) - 1                                ; Must start at 0 and end at record - 1
      PokeB(@recbuf\deleted + r, 0)                                 ; Poke 0's at position (r)
    Next r
    ;------------------------------------------------------------------------------------
    
  EndIf
  
Return
**It's late, I'm tired, time for Fred, the WonderRubberChicken!

Fangles woz ear orright den?

Posted: Sun Nov 10, 2002 2:31 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> Is it possible that the gadget cannot update that fast??

Probably. :) It works if you put While WindowEvent() : Wend at the
start of your processcurrentfile: routine, but I don't know how much
of a speed impact that would have on your app...

A couple of pointers for you: Why are you using API routines for INI
files, instead of the built-in Preferences library? Your comment says
that it's due to Mr Skunk's library being dead, but the Preferences
library has replaced it.

Second, your source has lots of dashes in the Procedure Browser due to
your comment lines being ;-----. Is that intended? If not, replace the
first dash with a space so they don't show up in the Procedure Browser
(ie. just use ; ----- instead).


PB - Registered PureBasic Coder

Posted: Mon Nov 11, 2002 3:34 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Originally posted by PB

> Is it possible that the gadget cannot update that fast??

Probably. :) It works if you put While WindowEvent() : Wend at the
start of your processcurrentfile: routine, but I don't know how much
of a speed impact that would have on your app...

A couple of pointers for you: Why are you using API routines for INI
files, instead of the built-in Preferences library? Your comment says
that it's due to Mr Skunk's library being dead, but the Preferences
library has replaced it.

Second, your source has lots of dashes in the Procedure Browser due to
your comment lines being ;-----. Is that intended? If not, replace the
first dash with a space so they don't show up in the Procedure Browser
(ie. just use ; ----- instead).
1: While WindowEvent() : Wend. DOn't see how that will work in this case as the gadget has been drawn alread (and flushed and I am writing to it at high speed

2. The built-in preferences library has had many problems in the past, the API routine has always worked. So why change it??

3. I like lots of dashes everywhere, helps me separate routines and block of code, makes it more readable for me :)

:):):):)


Fangles woz ear orright den?

Posted: Mon Nov 11, 2002 4:15 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> 1: While WindowEvent() : Wend. DOn't see how that will work in
> this case as the gadget has been drawn alread (and flushed and I
> am writing to it at high speed

Well, it works for me with your example. :)

> 2. The built-in preferences library has had many problems in the
> past, the API routine has always worked. So why change it??

Fair enough. :) Just trying to save you some typing, that's all.

> 3. I like lots of dashes everywhere, helps me separate routines
> and block of code, makes it more readable for me :)

I see. Your example had a big block of dashes in the Procedure Browser
for me, with no code in-between them, and hence my comment. It looks
like this in the browser:

> ----------------------------------------------------
> ----------------------------------------------------
> ----------------------------------------------------
> ----------------------------------------------------
> ----------------------------------------------------
> ----------------------------------------------------
> ----------------------------------------------------
> ----------------------------------------------------
> ----------------------------------------------------
> ----------------------------------------------------
> ----------------------------------------------------
> ----------------------------------------------------




PB - Registered PureBasic Coder

Posted: Mon Nov 11, 2002 4:58 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Originally posted by PB

> 1: While WindowEvent() : Wend. DOn't see how that will work in
> this case as the gadget has been drawn alread (and flushed and I
> am writing to it at high speed

Well, it works for me with your example. :)

> 2. The built-in preferences library has had many problems in the
> past, the API routine has always worked. So why change it??

Fair enough. :) Just trying to save you some typing, that's all.

> 3. I like lots of dashes everywhere, helps me separate routines
> and block of code, makes it more readable for me :)




PB - Registered PureBasic Coder
I don't use the procedure browser as I like to READ through my code to understand it. It's easier to understand what I am doing by slowly ssimilating the logic, rather than frenetically jumping around all over the place.

Everyone has their own way of doing things (I am from the school of old scrollers) :):):)

Fangles woz ear orright den?

Posted: Mon Nov 11, 2002 7:56 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> I don't use the procedure browser as I like to READ through my
> code to understand it.

Ah, okay. No problemo. :)


PB - Registered PureBasic Coder

Posted: Mon Nov 11, 2002 9:49 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Originally posted by PB

> I don't use the procedure browser as I like to READ through my
> code to understand it.

Ah, okay. No problemo. :)

PB - Registered PureBasic Coder
I wish I was a genius like you guys :):)

Fangles woz ear orright den?

Posted: Mon Nov 11, 2002 10:48 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> I wish I was a genius like you guys :):)

You're a good coder. You've got stuff in your sources that I haven't
even touched and/or know anything about myself. :)


PB - Registered PureBasic Coder

Posted: Mon Nov 11, 2002 4:10 pm
by BackupUser
Restored from previous forum. Originally posted by Berikco.

You should give the OS some time to update the gadget.
If you run your program in a long loop, like you do, windows will not update anything in your app's window.
Just move the debugger window over it, whole window is erased.
Windows only updates a app's window if the app uses the event API to return to the OS.
Only WindowEvent() in your long loop wil do it, just like PB said.
Even better would be tho use a thread if you have a long running process.



Regards,

Berikco

http://www.benny.zeb.be

Posted: Mon Nov 11, 2002 11:19 pm
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Originally posted by Berikco

You should give the OS some time to update the gadget.
If you run your program in a long loop, like you do, windows will not update anything in your app's window.
Just move the debugger window over it, whole window is erased.
Windows only updates a app's window if the app uses the event API to return to the OS.
Only WindowEvent() in your long loop wil do it, just like PB said.
Even better would be tho use a thread if you have a long running process.

Regards,

Berikco

http://www.benny.zeb.be
Uncle PB and Uncle Bericko have explained it again so my feeble brain will get it. Actually, I rather suspected I would have to go back to using a thread. Oh well.

Fangles woz ear orright den?