PROBLEM WITH REFRESH TEXT

Posted by Admin on 09-Sep-2010 09:56

Hi,

I've a window ABL Dialog . It's contains two buttons and two labels.

When click the button OK i've this code:

METHOD PRIVATE VOID okButton_Click (sender AS System.Object, e AS System.EventArgs):

THIS-OBJECT:DialogResult = System.Windows.Forms.DialogResult:Ok.

label1:text = "Borrando Código".

FOR EACH dliterales:

label2:TEXT = STRING(dliterales.codig).

DELETE dliterales.

END.

label1:TEXT = "Creando Código".

FOR EACH literales WHERE literales.traduc = YES NO-LOCK:

CREATE dliterales.

BUFFER-COPY literales TO dliterales.

label2:TEXT = STRING(dliterales.codig).

END.

THIS-OBJECT:Close ( ).

END METHOD.

The problem is don't view the labels , label1 and label2, don't refresh in the screen!!

All Replies

Posted by Matt Baker on 09-Sep-2010 10:13

The labels don't update because the ABL runs code in the UI thread.  You have written a very "tight" loop.  While this loop runs it doesn't allow the UI a chance to update.  It may be happening too fast for you to see it, or it may not be giving the UI a chance to repaint.

You could try adding a "process events." statement in the middle of your loop.  This will slow your loop down, but may allow the screen a chance to repaint.

Posted by Admin on 09-Sep-2010 10:21

You could try adding a "process events." statement in the middle of your loop. This will slow your loop down, but may allow the screen a chance to repaint.

When the slowing down becomes an issue, executing the PROCESS EVENTS. every 10th or 100th iteration is a good solution.

PROCESS EVENTS. can currently only be used in a method that has a VOID return type.

Posted by Admin on 09-Sep-2010 10:28

I had already tried what the PROCESS EVENTS and I do not work.
Any other solution? Is that the process takes a while, it's good that the user sees the screen that something is being processed, so do not think that is frozen the program.

Posted by Admin on 09-Sep-2010 10:36

I had already tried what the PROCESS EVENTS and I do not work.

Where in your code did you have that statement?

Posted by Matt Baker on 09-Sep-2010 10:42

Normally I would suggest using a progressbar at the bottom of the screen.

If you are using temp-tables, then for the first temp-table, since you are deleting everything, I would just do an "empty temp-table diliterales".  This is a whole lot faster and avoids the overhead of updating the UI.

For the second one, count the records, setup the progress bar with the correct number of "ticks" and then increment it as you delete records.  Make sure have an appropriate index on the second temp-table so the counting goes fast.

Here is an example:

define temp-table ttbig no-undo
    field x as integer.
   
   
define variable i as integer no-undo.

do i = 1 to 10000 :
    create ttbig.
    ttbig.x = i.
end.

define variable w as System.Windows.Forms.Form no-undo.

w = new System.Windows.Forms.Form().
w:size = new System.Drawing.Size(400, 200).
define variable p as System.Windows.Forms.ProgressBar no-undo.

p = new System.Windows.Forms.ProgressBar().

p:Size = new System.Drawing.Size(300, 30).
w:Controls:add(p).

define variable b as System.Windows.Forms.Button no-undo.
b = new System.Windows.Forms.Button().
b:size = new System.Drawing.Size(50, 30).
b:Text = "Delete Them All!!".
b:Location = new System.Drawing.Point(0, 50).
b:Click:subscribe("deleteThemAll").
w:Controls:add(b).

p:Maximum = i.

wait-for System.Windows.Forms.Application:Run(w).


procedure deleteThemAll:
    define input parameter sender as System.Object no-undo.
    define input parameter e as System.EventArgs no-undo.
   
    for each ttbig:
        p:Increment(1).
        delete ttbig.
    end.
   
end.

Posted by Admin on 09-Sep-2010 10:44

PROCESS EVENTS

label1:Text = "Borrando Código".

FOR EACH dliterales:

label2:

TEXT = STRING(dliterales.codig).

DELETE dliterales.

END.

label1:

TEXT = "Creando Código".

FOR EACH literales WHERE literales.traduc = YES NO-LOCK:

CREATE dliterales.

BUFFER-COPY literales TO dliterales.

label2:

TEXT = STRING(dliterales.codig).

END.

Posted by Admin on 09-Sep-2010 10:51

........

Posted by Admin on 09-Sep-2010 10:51

You should put the PROCESS EVENTS. inside the second FOR EACH loop.

Posted by Admin on 09-Sep-2010 11:44

Ok, thank you very much!!

I put inside the first and the second FOR EACH loop.

Posted by Admin on 09-Sep-2010 11:56

I put inside the first and the second FOR EACH loop.

When you can estimate the number of itereations before going thru the loop, I also prefer the ProgressBar control as suggested by Matt (or on Windows 7 a Taskbar Icon overlay). But you'll need a PROCESS EVENTS. then as well.

Posted by Admin on 10-Sep-2010 01:13

Ok, it also proved

This thread is closed