WriteLog Functions (Threads)

Share your advanced PureBasic knowledge/code with the community.
User avatar
mk-soft
Always Here
Always Here
Posts: 5336
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

WriteLog Functions (Threads)

Post by mk-soft »

I keep rewriting this code.
If someone can use the code, I'll put it down here. :wink:

Code: Select all

; Comment : Write Log Base
; Author  : mk-soft
; Create  : 27.08.2019
; Version : v1.01

; Enumeration CustemEvents #PB_Event_FirstCustomValue
;   #MyEventWriteLog
; EndEnumeration

; Declare MainWriteLog(Text.s)
; Declare Writelog(Text.s)

#WriteLogGadget = #Main_Listview_Status
#WriteLogMaxItems = 10000

Global flagWriteLogNoScroll = #False

Procedure MainWriteLog(Text.s) ; Call from Main Scope
  Protected cnt
  cnt = CountGadgetItems(#WriteLogGadget)
  If cnt >= #WriteLogMaxItems
    RemoveGadgetItem(#WriteLogGadget, 0)
    cnt -1
  EndIf
  AddGadgetItem(#WriteLogGadget, -1, Text)
  If Not flagWriteLogNoScroll
    SetGadgetState(#WriteLogGadget, cnt)
    SetGadgetState(#WriteLogGadget, -1)
  EndIf
EndProcedure

Procedure Writelog(Text.s) ; Call from Threads
  Protected *text.string
  *text = AllocateStructure(string)
  If *text
    *text\s = Text
    PostEvent(#MyEventWriteLog, 0, 0, 0, *text)
  EndIf
EndProcedure

Procedure DoEventWriteLog() ; Call from BindEvent
  Protected *text.string
  *text = EventData()
  If *text
    MainWriteLog(*text\s)
    FreeStructure(*text)
  EndIf
EndProcedure

BindEvent(#MyEventWriteLog, @DoEventWriteLog())

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
kinglestat
Enthusiast
Enthusiast
Posts: 732
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: WriteLog Functions (Threads)

Post by kinglestat »

This is nice
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
Post Reply