Topic: Counter

Hello All !

How to use component Counter ?
Is it useful to get number of records in a Base ?

Otherwise, how to get number of records by the way of a Script ?
I tried but I always get an error message (unidentified <nameoftable>)

Thnkas for your help

Jean B.

Re: Counter

Hello,

In this video you can see how to use component Counter
https://www.youtube.com/watch?v=bG30pqCrw8k#t=938


In script you can get value from component Counter
Form1.EditCounter1.Text


Example:
ShowMessage(IntToStr(Form1.EditCounter1.Text));

Dmitry.

Re: Counter

In the video linked here, there is nothing about the counter component!

Is it possible to script the component so it would count exactly what we want?

Re: Counter

No need script for work Counter component.


Time: 1.44 - Create a field for counter
Time: 14:58 - Set up the counter component

Dmitry.

5 (edited by tcoton 2015-01-26 12:08:49)

Re: Counter

Aaaaaah!!! Well actually I misunderstood the use of this component.

I thought it was there to give the ability to count rows like a "select count(*) where...." but here it is just displaying an value in a row.

I wish I could do that actually, it would be helpful in my current project, I would like to have a counter which displays the number of rows containing a given information.

Re: Counter

So, how could we create a counter which can filter specific informations?


for example:

I would like a small box which displays automatically a count of number of pc with status "Ready" and/or "To be Restaged"

I did not find yet a simple way of doing this and it really bothers me to add a button with such a query :

select count(id) as "Ready" from computers where id_status="3"
select count(id) as "To be Restaged  from computers where id_status="4"

Next step would be to change the background of the cell depending of the returned value... roll

Re: Counter

You can do it only using script and SQL query (SQLExecute function) then put result in TextBox


Also you can use event or timer for automatic updates this vallue.

Dmitry.

Re: Counter

Ok, so waiting for the possibility to auto execute a custom sql query in grid for a future release, how should I write this in my project?

procedure Form1_onShow (Sender: string; Action: string); //display form containing


this is the query which works great with a button:

SELECT *
FROM
(
   SELECT 'Nb Ready'  as "Status", COUNT(id)  AS Count FROM computers where id_status="3"
  UNION ALL   
  SELECT 'Nb Defect'  as "Status", COUNT(id)  AS Count FROM computers where id_status="2"
   UNION ALL
  SELECT 'Nb To be Restaged'  as "Status", COUNT(id)  AS Count FROM computers where id_status="4"

) temp

The funny thing is that the grid refreshes automatically when I change the status of a record, would it be possible to initiate this refresh when loading the form and hide the button?

Re: Counter

Yes, you can use event OnChange from TableGrid and event OnShow from Form1 for auto update.


Please, send me your project to support@drive-software.com
with link on this topic.


Thanks.

Dmitry.

Re: Counter

Actually, the solution is pretty simple as long as you well know the program!!

The trick here is to create a button and affect the query to this button but to set the visibility of the button to false and then simulate the click on showing the form or changing data!!

   //Auto count status
procedure Form1_GridSearch_OnChange (Sender: string);//Load automatically information into grid form1.readyGrid on change
begin
    Form1.Button1.Click;
end;

procedure Form1_OnShow (Sender: string; Action: string); // Load automatically information into grid form1.readyGrid
begin
    Form1.Button1.Click;
end;

Very clever smile


Thanks a lot again Dmitriy, you are a master!