Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread Afterscroll gives error
Sun, Jan 6 2008 1:49 PMPermanent Link

Peter van Mierlo
hi,

Within my datamodule there's a query component which i use for editing data.
One of the forms has a dbcheckbox. When this checkbox is checked, 2 fields
has to get enableded, otherwise disabled.

For testing the database has 3 records,
- for record 1 the value = true
- for record 2 the value =false
- for record 3 the value = true

i did try i with a simple piece of code, seel below. When i use this code in the
AfterScroll event i got a error and the app runs it WORKS, and for the right
records the fields will be disabled/enabled.
When i put it in the BeforeScroll event i do NOT get this error, but it's
not working propertly and enableds/disableds the fields for the wrong records.

What's wrong or is there a other method for solving this problem.

procedure TdmItem.qry_itemAfterScroll(DataSet: TDataSet);
begin
  if dmItem.qry_item.State in [dsBrowse] then begin
     if dmItem.qry_item.FieldByName('item_print_jn').value='Nee' then begin
        formItem.RzDBEdit_itemPrintTekst.enabled:=false;
        formItem.RzDBLookupComboBox_itemPrinter.Enabled:=false;
     end;
     if dmItem.qry_item.FieldByName('item_print_jn').value='Ja' then begin
        formItem.RzDBEdit_itemPrintTekst.enabled:=true;
        formItem.RzDBLookupComboBox_itemPrinter.Enabled:=true;
     end;
  end;
end;
Sun, Jan 6 2008 2:46 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Peter


If you have a table with three records

A
B
C

And you're currently on B then going downwards in the BeforeScroll the record will be B and in the AfterScroll it will be C going upwards in BeforeScroll it will be B and in the AfterScroll it will be A

I assume you want fields enabling/disabling depending on where you end up rather than where you start.

If you tell us what the error is we might be able to help.

Roy Lambert
Sun, Jan 6 2008 4:18 PMPermanent Link

Peter van Mierlo
Hi Roy,

When it's on the BeforeScroll event this happends :
record A = true and it shows enabled
record B = false and it shows enabled
record C = true and shows disabled

scrolling back to the first record from C to A
record B = false and it shows enabled
record A = true and it shows disabled

The AfterScroll does the right thing so with the
same code now in AfterScroll and running (F9) apps
it gives the following error :

raised exception class EaccesViolation with the mesage
Access violation at adres ....

The components that are has to be disabled are
part of a groupbox

Roy Lambert <roy.lambert@skynet.co.uk> wrote:

Peter


If you have a table with three records

A
B
C

And you're currently on B then going downwards in the BeforeScroll the record will be B and in the AfterScroll it will be C going upwards in
BeforeScroll it will be B and in the AfterScroll it will be A

I assume you want fields enabling/disabling depending on where you end up rather than where you start.

If you tell us what the error is we might be able to help.

Roy Lambert
Sun, Jan 6 2008 6:29 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Peter,

My guess is you are opening the query before all the components in
"formItem" are created; maybe because you are opening the query in the
 "OnCreate" event ...

About the question of using BeforeScroll or AfterScroll, I think you
want to use "AfterScroll", as Roy explained in his message.

Best regards
--
Fernando Dias
Easygate, Lda


Peter van Mierlo escreveu:
> hi,
>
> Within my datamodule there's a query component which i use for editing data.
> One of the forms has a dbcheckbox. When this checkbox is checked, 2 fields
> has to get enableded, otherwise disabled.
>
> For testing the database has 3 records,
> - for record 1 the value = true
> - for record 2 the value =false
> - for record 3 the value = true
>
> i did try i with a simple piece of code, seel below. When i use this code in the
> AfterScroll event i got a error and the app runs it WORKS, and for the right
> records the fields will be disabled/enabled.
> When i put it in the BeforeScroll event i do NOT get this error, but it's
> not working propertly and enableds/disableds the fields for the wrong records.
>
> What's wrong or is there a other method for solving this problem.
>
> procedure TdmItem.qry_itemAfterScroll(DataSet: TDataSet);
> begin
>    if dmItem.qry_item.State in [dsBrowse] then begin
>       if dmItem.qry_item.FieldByName('item_print_jn').value='Nee' then begin
>          formItem.RzDBEdit_itemPrintTekst.enabled:=false;
>          formItem.RzDBLookupComboBox_itemPrinter.Enabled:=false;
>       end;
>       if dmItem.qry_item.FieldByName('item_print_jn').value='Ja' then begin
>          formItem.RzDBEdit_itemPrintTekst.enabled:=true;
>          formItem.RzDBLookupComboBox_itemPrinter.Enabled:=true;
>       end;
>    end;
> end;
>
Mon, Jan 7 2008 5:22 AMPermanent Link

Peter van Mierlo
Hi Fernando,

Well the afterScroll does the thing i need, but creates the error, which
is not generated when using the same code in the BeforeScroll event
and thats what i can't figure out why it happends in AfterScroll and
not in BeforeScroll.

I have several datamodules which i use, because it's a very big
application. These datamodules will be opend first and after that
the forms are loaded. From that case it's possible what you descriped
about the which is loaded first. In the OnCreate event from the
datamodules all querie's are opened. Is there a better way WHEN
to open the queries instead of in the OnCreate event ?




Fernando Dias <fernandodias.removthis@easygate.com.pt> wrote:

Peter,

My guess is you are opening the query before all the components in
"formItem" are created; maybe because you are opening the query in the
 "OnCreate" event ...

About the question of using BeforeScroll or AfterScroll, I think you
want to use "AfterScroll", as Roy explained in his message.

Best regards
--
Fernando Dias
Easygate, Lda


Peter van Mierlo escreveu:
> hi,
>
> Within my datamodule there's a query component which i use for editing data.
> One of the forms has a dbcheckbox. When this checkbox is checked, 2 fields
> has to get enableded, otherwise disabled.
>
> For testing the database has 3 records,
> - for record 1 the value = true
> - for record 2 the value =false
> - for record 3 the value = true
>
> i did try i with a simple piece of code, seel below. When i use this code in the
> AfterScroll event i got a error and the app runs it WORKS, and for the right
> records the fields will be disabled/enabled.
> When i put it in the BeforeScroll event i do NOT get this error, but it's
> not working propertly and enableds/disableds the fields for the wrong records.
>
> What's wrong or is there a other method for solving this problem.
>
> procedure TdmItem.qry_itemAfterScroll(DataSet: TDataSet);
> begin
>    if dmItem.qry_item.State in [dsBrowse] then begin
>       if dmItem.qry_item.FieldByName('item_print_jn').value='Nee' then begin
>          formItem.RzDBEdit_itemPrintTekst.enabled:=false;
>          formItem.RzDBLookupComboBox_itemPrinter.Enabled:=false;
>       end;
>       if dmItem.qry_item.FieldByName('item_print_jn').value='Ja' then begin
>          formItem.RzDBEdit_itemPrintTekst.enabled:=true;
>          formItem.RzDBLookupComboBox_itemPrinter.Enabled:=true;
>       end;
>    end;
> end;
>
Mon, Jan 7 2008 7:02 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Peter,

> Well the afterScroll does the thing i need, but creates the error, which
> is not generated when using the same code in the BeforeScroll event
> and thats what i can't figure out why it happends in AfterScroll and
> not in BeforeScroll.

Because when you open a query, the "BeforeScroll" event is NOT fired, but
the "AfterScroll" is.
This is why I suspected the error is generated when you open the query.

> datamodules all querie's are opened. Is there a better way WHEN
> to open the queries instead of in the OnCreate event ?

There is no simple answer to that question, because it depends on the
structure of your App,
but a simple way to avoid the error and don't change much of the existing
code is to control the execution of AfterScroll with a boolean variable.
Someting like this:

procedure TdmItem.DataModuleCreate(Sender: TObject);
begin
  CanFireAfterScroll:=false;
  ( ... )
  Open the query, etc...
  ( ... )
  CanFireAfterScroll:=true;
end;

ant then, in the AfterScrollEvent:

procedure TdmItem.qry_itemAfterScroll(DataSet: TDataSet);
begin
 if not CanFireAfterScroll then exit;
 ( ... )
end;

I hope it helps.
Best regards.

--
Fernando Dias
Easygate, Lda

Mon, Jan 7 2008 9:40 AMPermanent Link

Peter van Mierlo
Hi Fernando,

Thanks...this does the trick, just what i needed
and i works perfect.

greetings
Peter
"Fernando Dias" <fernandodias.removthis@easygate.com.pt> wrote:

Peter,

> Well the afterScroll does the thing i need, but creates the error, which
> is not generated when using the same code in the BeforeScroll event
> and thats what i can't figure out why it happends in AfterScroll and
> not in BeforeScroll.

Because when you open a query, the "BeforeScroll" event is NOT fired, but
the "AfterScroll" is.
This is why I suspected the error is generated when you open the query.

> datamodules all querie's are opened. Is there a better way WHEN
> to open the queries instead of in the OnCreate event ?

There is no simple answer to that question, because it depends on the
structure of your App,
but a simple way to avoid the error and don't change much of the existing
code is to control the execution of AfterScroll with a boolean variable.
Someting like this:

procedure TdmItem.DataModuleCreate(Sender: TObject);
begin
  CanFireAfterScroll:=false;
  ( ... )
  Open the query, etc...
  ( ... )
  CanFireAfterScroll:=true;
end;

ant then, in the AfterScrollEvent:

procedure TdmItem.qry_itemAfterScroll(DataSet: TDataSet);
begin
 if not CanFireAfterScroll then exit;
 ( ... )
end;

I hope it helps.
Best regards.

--
Fernando Dias
Easygate, Lda

Image