Topic: Application crash

The following script crashes the app I used in?
I couldn't make it work.


procedure Form1_TreeView1_OnChange (Sender: string);
var
iRow2 ,c3: integer;
q2, iCol2: integer;
//
vi: integer;
begin
c3 := Form1.TreeView1.RowCount - 1;
q2 := Form1.TreeView1.Columns.Count-1;

Form1.TreeView1.columns[1].visible := false;
for vi := 0 to Form1.TreeView1.RowCount -1 do

   for iRow2 := 1 to c3 do
   if Form1.TreeView1.Cells[1,iRow2] = '(0)' then
   for iCol2 := 1 to q2 do Form1.TreeView1.Cell[iCol2,iRow2].textColor := $00B9B9B9;

   begin
   if Form1.TreeView1.Cells[1,vi] = 'red' then Form1.TreeView1.Cell[0,vi].textcolor := clred;
   end;
end;
Adam
God... please help me become the person my dog thinks I am.

2 (edited by sparrow 2023-07-08 21:10:46)

Re: Application crash

Hi,


Although this code contains an error, it does not cause a program crash or an error message.
This bug does not allow you to paint over text in red.


There is not enough information to give you a solution.
There are so many possible reasons. Check the number of output columns.

Re: Application crash

Hi Sparrow,


Thank you very much for your quick reply..............


You were right about crash cause as output columns. I found one of Derek's sample... Script works with calc. fields.


procedure Form1_TreeView1_OnChange (Sender: string);
begin
TreeView1OnChange01;
TreeView1OnChange02;
end;
//
procedure TreeView1OnChange01; //Old style tree items containing how many TG record
var
iRow2 ,c3: integer;
q2, iCol2: integer;
begin
c3 := Form1.TreeView1.RowCount - 1;
q2 := Form1.TreeView1.Columns.Count-1;
   for iRow2 := 1 to c3 do
   if Form1.TreeView1.Cells[1,iRow2] = '(0)' then
      for iCol2 := 1 to q2 do Form1.TreeView1.Cell[iCol2,iRow2].textColor := $00B9B9B9;
end;
//
procedure TreeView1OnChange02; //Treeview child items count and coloring
var  vi: integer;
begin
Form1.TreeView1.columns[1].visible := false;
for vi := 0 to Form1.TreeView1.RowCount -1 do
    begin
    if Form1.TreeView1.Cells[1,vi] = 'red' then Form1.TreeView1.Cell[0,vi].textcolor := clred;
    end;
end;

and two calc. field on tree db:
cfName

(case
when (select count(a.id) from ItemTree a 
where (a.parentid = ItemTree.id)) > 0 then name||' ('||(select count(a.id) from ItemTree a 
where (a.parentid = ItemTree.id))||')'       
else name
end)  

cftest:

(case
when (select count(a.id) from ItemTree a where (a.parentid = ItemTree.id)) > 0 then "red"
end) 

The above script credit belongs to Derek.

Adam
God... please help me become the person my dog thinks I am.

4 (edited by sparrow 2023-07-09 11:14:03)

Re: Application crash

Perhaps in your case you don't need calculated fields.
But the answer and help can be given to you by seeing an example of your task.
In any case, I'm glad your problem has been resolved.


P.S. Derek's script is written for a specific example and it is a whole together with calculated fields.
In the calculated fields, depending on the content of the database response, in the first case,
a string (x) is formed by joining, where x is a number. In the second case, if the value is greater than 0,
the string 'red' is formed. Then the corresponding value is decorated (painted over) in the script.


If your base or table output differs from Derek's example, you need to consider how many columns
you are outputting, which values you will be parsing to decorate, and which values to decorate.
And you should understand that these columns really should exist in the table.
Just rearranging it in your script will not work.
Several of Derek's embellishment procedures can be combined into one procedure,
but Derek's example is easier to navigate and easier to understand.

Re: Application crash

Hi Sparrow,


Here is a tester project without calc. fields.
I like the parent nodes to display child nodes count when there is some. Parents having child gets colored.

Post's attachments

Attachment icon Tester5.zip 8.84 kb, 64 downloads since 2023-07-09 

Adam
God... please help me become the person my dog thinks I am.

Re: Application crash

Based on Derek's code with modifications.
Two calculated fields with additions are left.
The parent field is printed with the number of children.
The 'color-cf' field instead of the string 'red' generates strings with the value 255 (red color) and (0) black color.
In the script, the color column is hidden and its value (255) is used to colorize the parents in the red color.
To change the color, translate the color value into an integer and substitute in the calculated field instead of 255.
For example, Green is 32768, Blue is 16711680.
You can also return to the traditional code with comparing values.

Post's attachments

Attachment icon Tester6.zip 329.86 kb, 72 downloads since 2023-07-09 

Re: Application crash

Привіт Sparrow,
I'd never have thought to set the color of a calculated field like that - very nice!
Derek.

Re: Application crash

Hi Derek )
Tried something new.  )

Re: Application crash

Hi Sparrow,


Thank you very much for your kind help............
Truly appreciated................

Adam
God... please help me become the person my dog thinks I am.

10 (edited by sparrow 2023-07-11 11:00:44)

Re: Application crash

Hi Adam, Hi Derek


Adam,
  I did a little experiment with our TreeView.
It turned out that the calculated fields of a simple design proposed by me and Derek
are not so effective on slightly larger data sets. Processing delays are related to the
ParenID field. At what a delay in MVD. Apparently the program also intensively works
with this field when forming a tree.
  I tried to optimize our calculated fields and you can see the result in this example.
In this example, the database contains just over 400 entries, and as you can see, the
difference is significant. You can use the new calculated fields in your examples.
If you have any problems, I will try to help you with adaptation and optimization.


p.s. Acceleration can also be achieved by indexing, but that's another story.

Post's attachments

Attachment icon Tester6-opt.zip 333.55 kb, 95 downloads since 2023-07-11 

Re: Application crash

Hi Sparrow,
It's certainly much quicker now (and the calculated field code is actually much simpler too).
Derek.

Re: Application crash

Hi Sparrow,
Great stuff...
Thank you very much.......

Adam
God... please help me become the person my dog thinks I am.