Skip to content

Commit c1b3dd1

Browse files
authored
Refactoring Row Selection (#23)
* Find and Select via TableRows * Refactor: TableRowFindAndSelect * Get RowTag via TableRows * Workaround: WebDataSource 0/1 based PrimaryKey * Update Note DebugMemoryIssues * Remove Workaround for Xojo 2024r2 PreReleases
1 parent 26a13d7 commit c1b3dd1

12 files changed

+103
-135
lines changed

webapp/containers/base/cntDatasourceBase.xojo_code

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ Implements WebDataSource
5454
If (Me.Table = Nil) Then Return Nil
5555

5656
Var rowIndex As Integer = Me.Table.SelectedRowIndex
57-
If (rowIndex < 0) Then Return Nil
57+
If (rowIndex < 0) Or (rowIndex > Me.TableRows.LastIndex) Then Return Nil
5858

59-
Return Me.Table.RowTagAt(rowIndex)
59+
Return Me.TableRows(rowIndex).Lookup("rowtag", Nil)
6060

6161
End Function
6262
#tag EndMethod
@@ -198,7 +198,6 @@ Implements WebDataSource
198198

199199
Var row As New WebListBoxRowData
200200
row.PrimaryKey = Me.TableRows(i).Lookup("id", -1).IntegerValue
201-
row.Tag = dictRow
202201

203202
For Each col As DatasourceColumn In Me.Columns
204203
Var colData As Variant = Me.TableRowColumnData(col, dictRow)
@@ -227,6 +226,8 @@ Implements WebDataSource
227226
End Select
228227
Next
229228

229+
dictRow.Value("rowtag") = dictRowTag
230+
230231
row.Tag = dictRowTag
231232
rows.Add(row)
232233

@@ -439,6 +440,35 @@ Implements WebDataSource
439440
End Sub
440441
#tag EndMethod
441442

443+
#tag Method, Flags = &h1
444+
Protected Function TableRowFindAndSelect(findByFields As Dictionary) As Boolean
445+
If (Me.TableRows = Nil) Or (Me.TableRows.LastIndex < 0) Then Return False
446+
If (findByFields = Nil) Or (findByFields.KeyCount < 1) Then Return False
447+
448+
Var tableRow As Dictionary
449+
Var bAllFieldsFound As Boolean
450+
For i As Integer = Me.TableRows.LastIndex DownTo 0
451+
tableRow = Me.TableRows(i)
452+
453+
bAllFieldsFound = True
454+
For Each field As Variant In findByFields.Keys
455+
If (tableRow.Lookup(field.StringValue, "").StringValue <> findByFields.Value(field).StringValue) Then
456+
bAllFieldsFound = False
457+
Exit 'Loop matching Fields
458+
End If
459+
Next
460+
461+
If (Not bAllFieldsFound) Then Continue 'searching next Table Row
462+
463+
Me.Table.SelectedRowIndex = i
464+
Return True
465+
Next
466+
467+
Return False
468+
469+
End Function
470+
#tag EndMethod
471+
442472
#tag Method, Flags = &h21
443473
Private Function UnsortedPrimaryKeys() As Integer()
444474
// Part of the WebDataSource interface.

webapp/containers/data/cntBackups.xojo_code

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -801,18 +801,12 @@ End
801801
Var sSelectAfterReload As String = esSelectAfterReload
802802
esSelectAfterReload = ""
803803

804-
Var bFound As Boolean = False
805-
For i As Integer = Me.Table.LastRowIndex DownTo 0
806-
Var rowTag As Dictionary = Me.Table.RowTagAt(i)
807-
If (rowTag IsA Dictionary) Then
808-
If (rowTag.Lookup("timestamp", "-").StringValue <> sSelectAfterReload) Then Continue
809-
Me.Table.SelectedRowIndex = i
810-
bFound = True
811-
Exit 'Loop
812-
End If
813-
Next
804+
Var findByFields As New Dictionary
805+
findByFields.Value("timestamp") = sSelectAfterReload
814806

815-
If (Not bFound) Then Me.Table.SelectedRowIndex = -1
807+
If (Not Me.TableRowFindAndSelect(findByFields)) Then
808+
Me.Table.SelectedRowIndex = -1
809+
End If
816810

817811
Me.RefreshButtons()
818812

webapp/containers/data/cntDatabases.xojo_code

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,18 +1145,12 @@ End
11451145
Var sSelectAfterReload As String = esSelectAfterReload
11461146
esSelectAfterReload = ""
11471147

1148-
Var bFound As Boolean = False
1149-
For i As Integer = Me.Table.LastRowIndex DownTo 0
1150-
Var rowTag As Dictionary = Me.Table.RowTagAt(i)
1151-
If (rowTag IsA Dictionary) Then
1152-
If (rowTag.Lookup("databasename", "").StringValue <> sSelectAfterReload) Then Continue
1153-
Me.Table.SelectedRowIndex = i
1154-
bFound = True
1155-
Exit 'Loop
1156-
End If
1157-
Next
1148+
Var findByFields As New Dictionary
1149+
findByFields.Value("databasename") = sSelectAfterReload
11581150

1159-
If (Not bFound) Then Me.Table.SelectedRowIndex = -1
1151+
If (Not Me.TableRowFindAndSelect(findByFields)) Then
1152+
Me.Table.SelectedRowIndex = -1
1153+
End If
11601154

11611155
Me.RefreshButtons()
11621156

webapp/containers/data/cntSchedules.xojo_code

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -933,18 +933,12 @@ End
933933
Var sSelectAfterReload As String = esSelectAfterReload
934934
esSelectAfterReload = ""
935935

936-
Var bFound As Boolean = False
937-
For i As Integer = Me.Table.LastRowIndex DownTo 0
938-
Var rowTag As Dictionary = Me.Table.RowTagAt(i)
939-
If (rowTag IsA Dictionary) Then
940-
If (rowTag.Lookup("schedname", "").StringValue <> sSelectAfterReload) Then Continue
941-
Me.Table.SelectedRowIndex = i
942-
bFound = True
943-
Exit 'Loop
944-
End If
945-
Next
936+
Var findByFields As New Dictionary
937+
findByFields.Value("schedname") = sSelectAfterReload
946938

947-
If (Not bFound) Then Me.Table.SelectedRowIndex = -1
939+
If (Not Me.TableRowFindAndSelect(findByFields)) Then
940+
Me.Table.SelectedRowIndex = -1
941+
End If
948942

949943
Me.RefreshButtons()
950944

webapp/containers/data/cntTablesIndexes.xojo_code

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -785,21 +785,13 @@ End
785785
Var sSelectAfterReload As Dictionary = edictSelectAfterReload
786786
edictSelectAfterReload = Nil
787787

788-
Var bFound As Boolean = False
789-
For i As Integer = Me.Table.LastRowIndex DownTo 0
790-
Var rowTag As Dictionary = Me.Table.RowTagAt(i)
791-
If (rowTag IsA Dictionary) Then
792-
If (rowTag.Lookup("type", "").StringValue = sSelectAfterReload.Lookup("type", "-").StringValue) And _
793-
(rowTag.Lookup("name", "").StringValue = sSelectAfterReload.Lookup("name", "-").StringValue) Then
794-
795-
Me.Table.SelectedRowIndex = i
796-
bFound = True
797-
Exit 'Loop
798-
End If
799-
End If
800-
Next
788+
Var findByFields As New Dictionary
789+
findByFields.Value("type") = sSelectAfterReload.Lookup("type", "-").StringValue
790+
findByFields.Value("name") = sSelectAfterReload.Lookup("name", "-").StringValue
801791

802-
If (Not bFound) Then Me.Table.SelectedRowIndex = -1
792+
If (Not Me.TableRowFindAndSelect(findByFields)) Then
793+
Me.Table.SelectedRowIndex = -1
794+
End If
803795

804796
Me.RefreshButtons()
805797

webapp/containers/information/cntClients.xojo_code

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -385,18 +385,12 @@ End
385385
Var iSelectAfterReload As Integer = eiSelectAfterReload
386386
eiSelectAfterReload = -1
387387

388-
Var bFound As Boolean = False
389-
For i As Integer = Me.Table.LastRowIndex DownTo 0
390-
Var rowTag As Dictionary = Me.Table.RowTagAt(i)
391-
If (rowTag IsA Dictionary) Then
392-
If (rowTag.Lookup("id", "").IntegerValue <> iSelectAfterReload) Then Continue
393-
Me.Table.SelectedRowIndex = i
394-
bFound = True
395-
Exit 'Loop
396-
End If
397-
Next
398-
399-
If (Not bFound) Then Me.Table.SelectedRowIndex = -1
388+
Var findByFields As New Dictionary
389+
findByFields.Value("id") = iSelectAfterReload
390+
391+
If (Not Me.TableRowFindAndSelect(findByFields)) Then
392+
Me.Table.SelectedRowIndex = -1
393+
End If
400394

401395
Me.RefreshButtons()
402396

@@ -434,7 +428,7 @@ End
434428
#tag Events btnRefresh
435429
#tag Event
436430
Sub Pressed()
437-
Self.TableLoad()
431+
Self.RefreshInfos()
438432

439433
End Sub
440434
#tag EndEvent

webapp/containers/security/cntEnginePreferences.xojo_code

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -789,23 +789,15 @@ End
789789
Var sSelectAfterReload As Dictionary = edictSelectAfterReload
790790
edictSelectAfterReload = Nil
791791

792-
Var bFound As Boolean = False
793-
For i As Integer = Me.Table.LastRowIndex DownTo 0
794-
Var rowTag As Dictionary = Me.Table.RowTagAt(i)
795-
If (rowTag IsA Dictionary) Then
796-
If(rowTag.Lookup("engine", "").StringValue = sSelectAfterReload.Lookup("engine", "-").StringValue) And _
797-
(rowTag.Lookup("groupname", "").StringValue = sSelectAfterReload.Lookup("groupname", "-").StringValue) And _
798-
(rowTag.Lookup("databasename", "").StringValue = sSelectAfterReload.Lookup("databasename", "-").StringValue) And _
799-
(rowTag.Lookup("key", "").StringValue = sSelectAfterReload.Lookup("key", "-").StringValue) Then
800-
801-
Me.Table.SelectedRowIndex = i
802-
bFound = True
803-
Exit 'Loop
804-
End If
805-
End If
806-
Next
807-
808-
If (Not bFound) Then Me.Table.SelectedRowIndex = -1
792+
Var findByFields As New Dictionary
793+
findByFields.Value("engine") = sSelectAfterReload.Lookup("engine", "-").StringValue
794+
findByFields.Value("groupname") = sSelectAfterReload.Lookup("groupname", "-").StringValue
795+
findByFields.Value("databasename") = sSelectAfterReload.Lookup("databasename", "-").StringValue
796+
findByFields.Value("key") = sSelectAfterReload.Lookup("key", "-").StringValue
797+
798+
If (Not Me.TableRowFindAndSelect(findByFields)) Then
799+
Me.Table.SelectedRowIndex = -1
800+
End If
809801

810802
Me.RefreshButtons()
811803

webapp/containers/security/cntGroups.xojo_code

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -535,18 +535,12 @@ End
535535
Var sSelectAfterReload As String = esSelectAfterReload
536536
esSelectAfterReload = ""
537537

538-
Var bFound As Boolean = False
539-
For i As Integer = Me.Table.LastRowIndex DownTo 0
540-
Var rowTag As Dictionary = Me.Table.RowTagAt(i)
541-
If (rowTag IsA Dictionary) Then
542-
If (rowTag.Lookup("groupname", "").StringValue <> sSelectAfterReload) Then Continue
543-
Me.Table.SelectedRowIndex = i
544-
bFound = True
545-
Exit 'Loop
546-
End If
547-
Next
548-
549-
If (Not bFound) Then Me.Table.SelectedRowIndex = -1
538+
Var findByFields As New Dictionary
539+
findByFields.Value("groupname") = sSelectAfterReload
540+
541+
If (Not Me.TableRowFindAndSelect(findByFields)) Then
542+
Me.Table.SelectedRowIndex = -1
543+
End If
550544

551545
Me.RefreshButtons()
552546

webapp/containers/security/cntPrivileges.xojo_code

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -765,23 +765,15 @@ End
765765
Var sSelectAfterReload As Dictionary = edictSelectAfterReload
766766
edictSelectAfterReload = Nil
767767

768-
Var bFound As Boolean = False
769-
For i As Integer = Me.Table.LastRowIndex DownTo 0
770-
Var rowTag As Dictionary = Me.Table.RowTagAt(i)
771-
If (rowTag IsA Dictionary) Then
772-
If (rowTag.Lookup("groupname", "").StringValue = sSelectAfterReload.Lookup("groupname", "-").StringValue) And _
773-
(rowTag.Lookup("privilege", "").StringValue = sSelectAfterReload.Lookup("privilege", "-").StringValue) And _
774-
(rowTag.Lookup("databasename", "").StringValue = sSelectAfterReload.Lookup("databasename", "-").StringValue) And _
775-
(rowTag.Lookup("tablename", "").StringValue = sSelectAfterReload.Lookup("tablename", "-").StringValue) Then
776-
777-
Me.Table.SelectedRowIndex = i
778-
bFound = True
779-
Exit 'Loop
780-
End If
781-
End If
782-
Next
783-
784-
If (Not bFound) Then Me.Table.SelectedRowIndex = -1
768+
Var findByFields As New Dictionary
769+
findByFields.Value("groupname") = sSelectAfterReload.Lookup("groupname", "-").StringValue
770+
findByFields.Value("privilege") = sSelectAfterReload.Lookup("privilege", "-").StringValue
771+
findByFields.Value("databasename") = sSelectAfterReload.Lookup("databasename", "-").StringValue
772+
findByFields.Value("tablename") = sSelectAfterReload.Lookup("tablename", "-").StringValue
773+
774+
If (Not Me.TableRowFindAndSelect(findByFields)) Then
775+
Me.Table.SelectedRowIndex = -1
776+
End If
785777

786778
Me.RefreshButtons()
787779

webapp/containers/security/cntUsers.xojo_code

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -889,18 +889,12 @@ End
889889
Var sSelectAfterReload As String = esSelectAfterReload
890890
esSelectAfterReload = ""
891891

892-
Var bFound As Boolean = False
893-
For i As Integer = Me.Table.LastRowIndex DownTo 0
894-
Var rowTag As Dictionary = Me.Table.RowTagAt(i)
895-
If (rowTag IsA Dictionary) Then
896-
If (rowTag.Lookup("username", "").StringValue <> sSelectAfterReload) Then Continue
897-
Me.Table.SelectedRowIndex = i
898-
bFound = True
899-
Exit 'Loop
900-
End If
901-
Next
892+
Var findByFields As New Dictionary
893+
findByFields.Value("username") = sSelectAfterReload
902894

903-
If (Not bFound) Then Me.Table.SelectedRowIndex = -1
895+
If (Not Me.TableRowFindAndSelect(findByFields)) Then
896+
Me.Table.SelectedRowIndex = -1
897+
End If
904898

905899
Me.RefreshButtons()
906900

0 commit comments

Comments
 (0)