Dev-Object

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

Hello everyone,

A command to allocate memory for the Data type member has been added. The following operators reuse it :
  • Copy()
    Read on file (Binary file)
    Open file (Binary file)
    Read file (Binary file)
    Read on file (encoded/encrypted file)
    Open file (encoded/encrypted file)
    Read file (encoded/encrypted file)
You can download the version 1.4.1 see the first post.

best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

Hello everyone,

Sorry to be so late and skip the upload of the version 1.4.2 but you can download the version 1.4.3 see the first post.

best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Cyllceaux
Enthusiast
Enthusiast
Posts: 457
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: Dev-Object

Post by Cyllceaux »

Hey there... I made some experiments.

Code: Select all

...
parent_null.q
*data
*data2
*data3
datalen.q
...
It creates Getter und Setter like:

Code: Select all

...
Get*data.i()
Get*data2.i()
Get*data3.i()
...
Set*data(*P_*data.)
Set*data2(*P_*data2.)
Set*data3(*P_*data3.)
...
The Free:

Code: Select all

...
If *This\*data <> #Null
   *This\*data\Free()
EndIf
...
And Constructor:

Code: Select all

...
If *P_*data <> #Null
   *This\*data = *P_*data
Else
   *This\*data = ::New()
EndIf
...
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

It's normal behaviors, for Data Type fields you have to add some information as comment like this :

Code: Select all

parent_null.q
data1.i ; Data, datalen
data2.i ; Data, datalen
data3.i ; Data, datalen
datalen.q
See the help topic about : The Raw data type

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

StarBootics wrote:It's normal behaviors, for Data Type fields you have to add some information as comment like this :

Code: Select all

parent_null.q
data1.i ; Data, datalen
data2.i ; Data, datalen
data3.i ; Data, datalen
datalen.q
See the help topic about : The Raw data type

Best regards
StarBootics
I forget to precise that you need to place fields like that :

Code: Select all

parent_null.q
datalen.q
data1.i ; Data, datalen
data2.i ; Data, datalen
data3.i ; Data, datalen
It's important to place them like that if you want to save the data on binary/encoded/encrypted file.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

Hello everyone,

The version 1.4.4 is available for download. In order to reduce function calls and improve speed, the Plus and Minus math operators has been modified. They are no longer calling the constructor. The Product and Divide operator has been also modified to be more like the Plus and Minus operators.

See the first post to download the latest source code.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

Hello everyone,

The version 1.4.5 is available for download. What's new in this version ?

Linked list operator Add Element Ex added
Linked list operator Insert Element added
Linked list operator Insert Element Ex added

See the first post to download the latest source code.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

Hello everyone,

The version 1.4.6 is available for download. What's new in this version ?

Correction of a small bug in the AddMember() methods in the Class object.

See the first post to download the latest source code.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

Hello everyone,

The version 1.4.7 is available for download. What's new in this version ?
  • Map operators Add Element Ex added
  • Many help files corrections
  • Suppression of the "Max - Module.pb" and modification of the "Comments" object
See the first post to download the latest source code.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

Hello everyone,

The version 1.4.8 is available for download. What's new in this version ?
  • Correction in the "Help" object methods "ScanPath()" The proper help file path has been sent to the MarkDown gadget correctly.
  • Many help files corrections
  • Adjustment for Linux about the inclusion of the "WindowBackgroundColor" module. This module is needed for a correction hack of the ScrollAreaGadget() black background color by default.
See the first post to download the latest source code.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

Hello everyone,

The version 1.4.9 is available for download. What's new in this version ?

- Two new integrated tools
  • Sanity Checker
  • Garbage Collector
- Help file added about the integrated tools

See the first post to download the latest source code.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Mr.L
Enthusiast
Enthusiast
Posts: 104
Joined: Sun Oct 09, 2011 7:39 am

Re: Dev-Object

Post by Mr.L »

Thanks for the source code, but I have to admit - I have no clue what I can do with it or even how to generate code :wink:
I tried to follow your example but no source code has been generated.
Can you explain to me shortly what are the benefits of your program and how I have to use it?
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

Mr.L wrote: Sat May 15, 2021 9:05 pm Thanks for the source code, but I have to admit - I have no clue what I can do with it or even how to generate code :wink:
I tried to follow your example but no source code has been generated.
Can you explain to me shortly what are the benefits of your program and how I have to use it?
Euh OK ... But First are you capable to compile the program on your computer to have it up and running ?

If not I need to know the operating system you are using. Because I never try on a MAC OS computer and the program might need some adjustment.

I'm guessing you are on Windows or Linux operating system and you have the program up and running if is the case let's follow the example of a RecentFiles system.

Let's have a look again on what the program look like :

Image

So you have to set the program on the "Object" tab and enter RecentFiles for the Object name and HistoricSize.a and List FileNames.s()

For this particular example we want the all the methods we see in the two following images:

Image

Image

Once they are selected you need to click on the Green and Purple gears button to generate the source code. The program will generate the source code and make the "Source" tab active by it's own. You can click on the Floppy disk button to save the source code or click on the Clipboard button to send a copy of the source code in the Clipboard and paste it in the PB IDE right away.

Image

You should end up with a source code like that one :

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; AUTOMATICALLY GENERATED CODE, DO NOT MODIFY
; UNLESS YOU REALLY, REALLY, REALLY MEAN IT !!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Code generated by : Dev-Object - V1.4.9
; Project name : the project name here
; File name : File name here
; File Version : 0.0.0
; Programmation : In progress
; Programmed by : StarBootics
; Creation Date : 15-05-2021
; Last update : 15-05-2021
; Coded for PureBasic : V5.73 LTS
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule RecentFiles
  
  Interface RecentFiles
    
    GetHistoricSize.a()
    GetFileNames.s()
    SetHistoricSize(P_HistoricSize.a)
    SetFileNames(P_FileNames.s)
    LinearSearchFileNames.l(P_FileNames.s)
    AddFileNames()
    SelectFileNames.i(P_Index.l)
    FirstFileNames.i()
    LastFileNames.i()
    PreviousFileNames.i()
    NextFileNames.i()
    DeleteFileNames()
    ResetFileNames()
    ClearFileNames()
    FileNamesIndex.l()
    FileNamesSize.l()
    ReadPrefs(P_GroupName.s)
    WritePrefs(P_GroupName.s)
    Free()
    
  EndInterface
  
  ; Declare Free(*This)
  Declare.i New()
  
EndDeclareModule

Module RecentFiles
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Structure declaration <<<<<

  Structure Private_Members
    
    VirtualTable.i
    HistoricSize.l
    List FileNames.s()
    
  EndStructure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The observators <<<<<

  Procedure.a GetHistoricSize(*This.Private_Members)
    
    ProcedureReturn *This\HistoricSize
  EndProcedure
  
  Procedure.s GetFileNames(*This.Private_Members)
    
    ProcedureReturn *This\FileNames()
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The mutators <<<<<

  Procedure SetHistoricSize(*This.Private_Members, P_HistoricSize.a)
    
    *This\HistoricSize = P_HistoricSize
    
  EndProcedure
  
  Procedure SetFileNames(*This.Private_Members, P_FileNames.s)
    
    *This\FileNames() = P_FileNames
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The linear search linked list operator(s) <<<<<

  Procedure.l LinearSearchFileNames(*This.Private_Members, P_FileNames.s)
    
    IsFoundAtIndex.l = -1
    
    ForEach *This\FileNames()
      
      If P_FileNames = *This\FileNames()
        IsFoundAtIndex = ListIndex(*This\FileNames())
        Break
      EndIf
      
    Next
    
    ProcedureReturn IsFoundAtIndex
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Add to linked list operator(s) <<<<<

  Procedure AddFileNames(*This.Private_Members)
    
    AddElement(*This\FileNames())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Select in linked list operator(s) <<<<<

  Procedure.i SelectFileNames(*This.Private_Members, P_Index.l)
    
    ProcedureReturn SelectElement(*This\FileNames(), P_Index)
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The First element in linked list operator(s) <<<<<

  Procedure.i FirstFileNames(*This.Private_Members)
    
    ProcedureReturn FirstElement(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Last element in linked list operator(s) <<<<<

  Procedure.i LastFileNames(*This.Private_Members)
    
    ProcedureReturn LastElement(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Previous element in linked list operator(s) <<<<<

  Procedure.i PreviousFileNames(*This.Private_Members)
    
    ProcedureReturn PreviousElement(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Next element in linked list operator(s) <<<<<

  Procedure.i NextFileNames(*This.Private_Members)
    
    ProcedureReturn NextElement(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Delete element from linked list operator(s) <<<<<

  Procedure DeleteFileNames(*This.Private_Members)
    
    DeleteElement(*This\FileNames())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Reset linked list operator(s) <<<<<

  Procedure ResetFileNames(*This.Private_Members)
    
    ResetList(*This\FileNames())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Clear linked list operator(s) <<<<<

  Procedure ClearFileNames(*This.Private_Members)
    
    ClearList(*This\FileNames())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Index in the linked list operator(s) <<<<<

  Procedure.l FileNamesIndex(*This.Private_Members)
    
    ProcedureReturn ListIndex(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Size of the linked list operator(s) <<<<<

  Procedure.l FileNamesSize(*This.Private_Members)
    
    ProcedureReturn ListSize(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Read preferences group <<<<<

  Procedure ReadPrefs(*This.Private_Members, P_GroupName.s)
    
    PreferenceGroup(P_GroupName)
    
    *This\HistoricSize = ReadPreferenceLong("HistoricSize", *This\HistoricSize)
    
    FileNames_Max = ReadPreferenceLong("FileNames_Max", 0) - 1
    
    For FileNamesID = 0 To FileNames_Max
      AddElement(*This\FileNames())
      *This\FileNames() = ReadPreferenceString("FileNames_" + Str(FileNamesID), *This\FileNames())
    Next
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Write preferences group <<<<<

  Procedure WritePrefs(*This.Private_Members, P_GroupName.s)
    
    PreferenceGroup(P_GroupName)
    
    WritePreferenceLong("HistoricSize", *This\HistoricSize)
    
    WritePreferenceLong("FileNames_Max", ListSize(*This\FileNames()))
    
    ForEach *This\FileNames()
      WritePreferenceString("FileNames_" + Str(ListIndex(*This\FileNames())), *This\FileNames())
    Next
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Destructor <<<<<

  Procedure Free(*This.Private_Members)
    
    FreeStructure(*This)
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Constructor <<<<<

  Procedure.i New()
    
    *This.Private_Members = AllocateStructure(Private_Members)
    *This\VirtualTable = ?START_METHODS
    
    ; *This\HistoricSize = 0
    
    ProcedureReturn *This
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Virtual Table Entries <<<<<

  DataSection
    START_METHODS:
    Data.i @GetHistoricSize()
    Data.i @GetFileNames()
    Data.i @SetHistoricSize()
    Data.i @SetFileNames()
    Data.i @LinearSearchFileNames()
    Data.i @AddFileNames()
    Data.i @SelectFileNames()
    Data.i @FirstFileNames()
    Data.i @LastFileNames()
    Data.i @PreviousFileNames()
    Data.i @NextFileNames()
    Data.i @DeleteFileNames()
    Data.i @ResetFileNames()
    Data.i @ClearFileNames()
    Data.i @FileNamesIndex()
    Data.i @FileNamesSize()
    Data.i @ReadPrefs()
    Data.i @WritePrefs()
    Data.i @Free()
    END_METHODS:
  EndDataSection
  
EndModule

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code generated in : 00.001 seconds (287000.00 lines/second) <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
You are asking for the benefit what about this :
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code generated in : 00.001 seconds (287000.00 lines/second) <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
At this point the RecentFiles is not operational because two methods needs to be added.

Code: Select all

InsertNewFile(P_NewFileName.s)
SanityCheck()
Let's add them and put final touches to the code :

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; AUTOMATICALLY GENERATED CODE, DO NOT MODIFY
; UNLESS YOU REALLY, REALLY, REALLY MEAN IT !!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Code generated by : Dev-Object - V1.0.0 Beta
; Project name : RecentFiles Object
; File name : RecentFiles - OOP.pb
; File Version : 1.0.0
; Programmation : OK
; Programmed by : StarBootics
; Creation Date : 16-03-2020
; Last update : 29-10-2020
; Coded for PureBasic : V5.72 LTS Beta 2
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule RecentFiles
  
  Interface RecentFiles
    
    GetHistoricSize.a()
    GetFileNames.s()
    SetHistoricSize(P_HistoricSize.a)
    SetFileNames(P_FileNames.s)
    LinearSearchFileNames.l(P_FileNames.s)
    AddFileNames()
    SelectFileNames.i(P_Index.l)
    FirstFileNames.i()
    LastFileNames.i()
    PreviousFileNames.i()
    NextFileNames.i()
    DeleteFileNames()
    ResetFileNames()
    ClearFileNames()
    FileNamesIndex.l()
    FileNamesSize.l()
    ReadPrefs(P_GroupName.s)
    WritePrefs(P_GroupName.s)
    InsertNewFile(P_NewFileName.s)
    SanityCheck()
    Free()
    
  EndInterface
  
  Declare.i New(P_HistoricSize.a = 20)
  
EndDeclareModule

Module RecentFiles
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Structure declaration <<<<<

  Structure Private_Members
    
    VirtualTable.i
    HistoricSize.a
    List FileNames.s()
    
  EndStructure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The observators <<<<<

  Procedure.a GetHistoricSize(*This.Private_Members)
    
    ProcedureReturn *This\HistoricSize
  EndProcedure
  
  Procedure.s GetFileNames(*This.Private_Members)
    
    ProcedureReturn *This\FileNames()
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The mutators <<<<<

  Procedure SetHistoricSize(*This.Private_Members, P_HistoricSize.a)
    
    *This\HistoricSize = P_HistoricSize
    
    While ListSize(*This\FileNames()) > *This\HistoricSize
      LastElement(*This\FileNames())
      DeleteElement(*This\FileNames())
    Wend
    
  EndProcedure
  
  Procedure SetFileNames(*This.Private_Members, P_FileNames.s)
    
    *This\FileNames() = P_FileNames
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The linear search linked list operator(s) <<<<<

  Procedure.l LinearSearchFileNames(*This.Private_Members, P_FileNames.s)
    
    IsFoundAtIndex.l = -1
    
    ForEach *This\FileNames()
      
      If P_FileNames = *This\FileNames()
        IsFoundAtIndex = ListIndex(*This\FileNames())
        Break
      EndIf
      
    Next
    
    ProcedureReturn IsFoundAtIndex
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Add to linked list operator(s) <<<<<

  Procedure AddFileNames(*This.Private_Members)
    
    AddElement(*This\FileNames())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Select in linked list operator(s) <<<<<

  Procedure.i SelectFileNames(*This.Private_Members, P_Index.l)
    
    ProcedureReturn SelectElement(*This\FileNames(), P_Index)
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The First element in linked list operator(s) <<<<<

  Procedure.i FirstFileNames(*This.Private_Members)
    
    ProcedureReturn FirstElement(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Last element in linked list operator(s) <<<<<

  Procedure.i LastFileNames(*This.Private_Members)
    
    ProcedureReturn LastElement(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Previous element in linked list operator(s) <<<<<

  Procedure.i PreviousFileNames(*This.Private_Members)
    
    ProcedureReturn PreviousElement(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Next element in linked list operator(s) <<<<<

  Procedure.i NextFileNames(*This.Private_Members)
    
    ProcedureReturn NextElement(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Delete element from linked list operator(s) <<<<<

  Procedure DeleteFileNames(*This.Private_Members)
    
    DeleteElement(*This\FileNames())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Reset linked list operator(s) <<<<<

  Procedure ResetFileNames(*This.Private_Members)
    
    ResetList(*This\FileNames())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Clear linked list operator(s) <<<<<

  Procedure ClearFileNames(*This.Private_Members)
    
    ClearList(*This\FileNames())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Index in the linked list operator(s) <<<<<

  Procedure.l FileNamesIndex(*This.Private_Members)
    
    ProcedureReturn ListIndex(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Size of the linked list operator(s) <<<<<

  Procedure.l FileNamesSize(*This.Private_Members)
    
    ProcedureReturn ListSize(*This\FileNames())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Read preferences group <<<<<

  Procedure ReadPrefs(*This.Private_Members, P_GroupName.s)
    
    PreferenceGroup(P_GroupName)
    
    *This\HistoricSize = ReadPreferenceLong("HistoricSize", *This\HistoricSize)
    
    FileNames_Max = ReadPreferenceLong("FileNames_Max", 0) - 1
    
    For FileNamesID = 0 To FileNames_Max
      AddElement(*This\FileNames())
      *This\FileNames() = ReadPreferenceString("FileNames_" + Str(FileNamesID), *This\FileNames())
    Next
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Write preferences group <<<<<

  Procedure WritePrefs(*This.Private_Members, P_GroupName.s)
    
    PreferenceGroup(P_GroupName)
    
    WritePreferenceLong("HistoricSize", *This\HistoricSize)
    
    WritePreferenceLong("FileNames_Max", ListSize(*This\FileNames()))
    
    ForEach *This\FileNames()
      WritePreferenceString("FileNames_" + Str(ListIndex(*This\FileNames())), *This\FileNames())
    Next
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< InsertNewFile Operator <<<<<
  
  Procedure InsertNewFile(*This.Private_Members, P_NewFileName.s)
    
    If LinearSearchFileNames(*This, P_NewFileName) = -1
      
      ResetList(*This\FileNames())
      AddElement(*This\FileNames())
      *This\FileNames() = P_NewFileName
      
    Else
      
      DeleteElement(*This\FileNames())
      ResetList(*This\FileNames())
      AddElement(*This\FileNames())
      *This\FileNames() = P_NewFileName
      
    EndIf
    
    If ListSize(*This\FileNames()) > *This\HistoricSize
      LastElement(*This\FileNames())
      DeleteElement(*This\FileNames())
    EndIf 
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< SanityCheck Operator <<<<<
  
  Procedure SanityCheck(*This.Private_Members)
    
    ForEach *This\FileNames()
      
      If FileSize(*This\FileNames()) = -1
        DeleteElement(*This\FileNames(), 1)
      EndIf
      
    Next
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Destructor <<<<<

  Procedure Free(*This.Private_Members)
    
    FreeStructure(*This)
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Constructor <<<<<

  Procedure.i New(P_HistoricSize.a = 20)
    
    *This.Private_Members = AllocateStructure(Private_Members)
    *This\VirtualTable = ?START_METHODS
    
    *This\HistoricSize = P_HistoricSize
    
    ProcedureReturn *This
  EndProcedure
  
  DataSection
    START_METHODS:
    Data.i @GetHistoricSize()
    Data.i @GetFileNames()
    Data.i @SetHistoricSize()
    Data.i @SetFileNames()
    Data.i @LinearSearchFileNames()
    Data.i @AddFileNames()
    Data.i @SelectFileNames()
    Data.i @FirstFileNames()
    Data.i @LastFileNames()
    Data.i @PreviousFileNames()
    Data.i @NextFileNames()
    Data.i @DeleteFileNames()
    Data.i @ResetFileNames()
    Data.i @ClearFileNames()
    Data.i @FileNamesIndex()
    Data.i @FileNamesSize()
    Data.i @ReadPrefs()
    Data.i @WritePrefs()
    Data.i @InsertNewFile()
    Data.i @SanityCheck()
    Data.i @Free()
    END_METHODS:
  EndDataSection
  
EndModule

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code generated in : 00.001 seconds (284000.00 lines/second) <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

CompilerIf #PB_Compiler_IsMainFile
  
  RecentFiles.RecentFiles::RecentFiles = RecentFiles::New(5)
  
  For Index = 0 To 5
    
    If CreateFile(Index, "Fichier " + Str(Index) + ".txt")
      WriteString(Index, "Test file - Fichier test : " + Str(Index))
      CloseFile(Index)
      RecentFiles\InsertNewFile("Fichier " + Str(Index) + ".txt")
    EndIf
    
  Next
  
  RecentFiles\ResetFileNames()
  
  While RecentFiles\NextFileNames()
    Debug RecentFiles\GetFileNames()
  Wend
  
  RecentFiles\InsertNewFile("Fichier " + Str(3) + ".txt")
  Debug ""
  
  RecentFiles\ResetFileNames()
  
  While RecentFiles\NextFileNames()
    Debug RecentFiles\GetFileNames()
  Wend
  
  RecentFiles\InsertNewFile("Fichier " + Str(6) + ".txt")
  Debug ""
  
  If RecentFiles\FirstFileNames()
    
    Repeat 
      Debug RecentFiles\GetFileNames()
    Until RecentFiles\NextFileNames() = #Null
    
  EndIf
  
  RecentFiles\SetHistoricSize(4)
  
  Debug ""
  RecentFiles\ResetFileNames()
  
  While RecentFiles\NextFileNames()
    Debug RecentFiles\GetFileNames()
  Wend
  
  RecentFiles\SanityCheck()
  
  Debug ""
  RecentFiles\ResetFileNames()
  
  While RecentFiles\NextFileNames()
    Debug RecentFiles\GetFileNames()
  Wend
  
  For Index = 0 To 5
    DeleteFile("Fichier " + Str(Index) + ".txt")
  Next
  
  RecentFiles\Free()
  
CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
After that it should be very easy to integrate this RecentFiles system into any of your projects.

Any question ?

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Mr.L
Enthusiast
Enthusiast
Posts: 104
Joined: Sun Oct 09, 2011 7:39 am

Re: Dev-Object

Post by Mr.L »

Thanks, StarBootics,
following your example, this is the generated code.
As you can see, the method names are not generated correctly (e.g. in your generated code the method is called GetFileNames.s(), in my code simply Get.i())

(Yes, I'm on Windows 10)

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; AUTOMATICALLY GENERATED CODE, DO NOT MODIFY
; UNLESS YOU REALLY, REALLY, REALLY MEAN IT !!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Code generated by : Dev-Object - V1.4.9
; Project name : the project name here
; File name : File name here
; File Version : 0.0.0
; Programmation : In progress
; Programmed by : Your name
; AKA : Nick name
; E-mail : Email
; Creation Date : 16-05-2021
; Last update : 16-05-2021
; Coded for PureBasic : V5.72
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule RecentFiles
  
  Interface RecentFiles
    
    GetHistoricSize.a()
    Get.i()
    SetHistoricSize(P_HistoricSize.a)
    Set(*P_.)
    Add()
    AddEx(*P_.)
    Insert()
    InsertEx(*P_.)
    Select.i(P_Index.l)
    First.i()
    Last.i()
    Previous.i()
    Next.i()
    Delete()
    Reset()
    Clear()
    Index.l()
    Size.l()
    ReadPrefs(P_GroupName.s)
    WritePrefs(P_GroupName.s)
    Free()
    
  EndInterface
  
  ; Declare Free(*This)
  Declare.i New()
  
EndDeclareModule

Module RecentFiles
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Structure declaration <<<<<

  Structure Private_Members
    
    VirtualTable.i
    HistoricSize.a
    List  FileNames.s()
    
  EndStructure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The observators <<<<<

  Procedure.a GetHistoricSize(*This.Private_Members)
    
    ProcedureReturn *This\HistoricSize
  EndProcedure
  
  Procedure.i Get(*This.Private_Members)
    
    ProcedureReturn *This\()
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The mutators <<<<<

  Procedure SetHistoricSize(*This.Private_Members, P_HistoricSize.a)
    
    *This\HistoricSize = P_HistoricSize
    
  EndProcedure
  
  Procedure Set(*This.Private_Members, *P_.)
    
    If *This\() <> #Null
      *This\()\Free()
    EndIf
    
    *This\() = *P_
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Add to linked list operator(s) <<<<<

  Procedure Add(*This.Private_Members)
    
    AddElement(*This\())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The AddEx to linked list operator(s) <<<<<

  Procedure AddEx(*This.Private_Members, *P_.)
    
    AddElement(*This\())
    *This\() = *P_
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Insert in linked list operator(s) <<<<<

  Procedure Insert(*This.Private_Members)
    
    InsertElement(*This\())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The InsertEx in linked list operator(s) <<<<<

  Procedure InsertEx(*This.Private_Members, *P_.)
    
    InsertElement(*This\())
    *This\() = *P_
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Select in linked list operator(s) <<<<<

  Procedure.i Select(*This.Private_Members, P_Index.l)
    
    ProcedureReturn SelectElement(*This\(), P_Index)
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The First element in linked list operator(s) <<<<<

  Procedure.i First(*This.Private_Members)
    
    ProcedureReturn FirstElement(*This\())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Last element in linked list operator(s) <<<<<

  Procedure.i Last(*This.Private_Members)
    
    ProcedureReturn LastElement(*This\())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Previous element in linked list operator(s) <<<<<

  Procedure.i Previous(*This.Private_Members)
    
    ProcedureReturn PreviousElement(*This\())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Next element in linked list operator(s) <<<<<

  Procedure.i Next(*This.Private_Members)
    
    ProcedureReturn NextElement(*This\())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Delete element from linked list operator(s) <<<<<

  Procedure Delete(*This.Private_Members)
    
    If *This\() <> #Null
      *This\()\Free()
    EndIf
    
    DeleteElement(*This\())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Reset linked list operator(s) <<<<<

  Procedure Reset(*This.Private_Members)
    
    ResetList(*This\())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Clear linked list operator(s) <<<<<

  Procedure Clear(*This.Private_Members)
    
    ForEach *This\()
      If *This\() <> #Null
        *This\()\Free()
      EndIf
    Next
    
    ClearList(*This\())
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Index in the linked list operator(s) <<<<<

  Procedure.l Index(*This.Private_Members)
    
    ProcedureReturn ListIndex(*This\())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Size of the linked list operator(s) <<<<<

  Procedure.l Size(*This.Private_Members)
    
    ProcedureReturn ListSize(*This\())
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Read preferences group <<<<<

  Procedure ReadPrefs(*This.Private_Members, P_GroupName.s)
    
    PreferenceGroup(P_GroupName)
    
    *This\HistoricSize = ReadPreferenceLong("HistoricSize", *This\HistoricSize)
    
    _Max = ReadPreferenceLong("_Max", 0) - 1
    
    For ID = 0 To _Max
      AddElement(*This\())
      *This\() = ::New()
      ; NOT SUPPORTED YET
    Next
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Write preferences group <<<<<

  Procedure WritePrefs(*This.Private_Members, P_GroupName.s)
    
    PreferenceGroup(P_GroupName)
    
    WritePreferenceLong("HistoricSize", *This\HistoricSize)
    
    WritePreferenceLong("_Max", ListSize(*This\()))
    
    ForEach *This\()
      ; NOT SUPPORTED YET
    Next
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Destructor <<<<<

  Procedure Free(*This.Private_Members)
    
    ForEach *This\()
      If *This\() <> #Null
        *This\()\Free()
      EndIf
    Next
    
    FreeStructure(*This)
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Constructor <<<<<

  Procedure.i New()
    
    *This.Private_Members = AllocateStructure(Private_Members)
    *This\VirtualTable = ?START_METHODS
    
    ; *This\HistoricSize = 0
    
    ProcedureReturn *This
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Virtual Table Entries <<<<<

  DataSection
    START_METHODS:
    Data.i @GetHistoricSize()
    Data.i @Get()
    Data.i @SetHistoricSize()
    Data.i @Set()
    Data.i @Add()
    Data.i @AddEx()
    Data.i @Insert()
    Data.i @InsertEx()
    Data.i @Select()
    Data.i @First()
    Data.i @Last()
    Data.i @Previous()
    Data.i @Next()
    Data.i @Delete()
    Data.i @Reset()
    Data.i @Clear()
    Data.i @Index()
    Data.i @Size()
    Data.i @ReadPrefs()
    Data.i @WritePrefs()
    Data.i @Free()
    END_METHODS:
  EndDataSection
  
EndModule

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code generated in : 00.001 seconds (322000.00 lines/second) <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Dev-Object

Post by StarBootics »

Mr.L wrote: Sun May 16, 2021 12:24 pm Thanks, StarBootics,
following your example, this is the generated code.
As you can see, the method names are not generated correctly (e.g. in your generated code the method is called GetFileNames.s(), in my code simply Get.i())

(Yes, I'm on Windows 10)
You just discovered a bug. Between the List keyword and FileNames.s() you have two space character. I will have a closer look to this problem it should have worked anyway.

Thanks for reporting that.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Post Reply