Board index » delphi » Can i get help on writing an afterscroll event

Can i get help on writing an afterscroll event

I have been setting a TDateTimePicker date value on a form from the
TTableAfterScroll event that is on my datamodule.
Now i realise that i can't directly access this form from the datamodule so
i need to try to set the date value when on the form, and the user changes
records.
Is it possible to write a method that will allow me to set the TDateTime
picker date value each time the record changes. I can't use the OnClick
event of the DBNavigator because the user has the ability to filter records,
and therefore that event would not be called.

I have looked at the Help on the After scroll event and it says that you can
write an AfterScroll Event handler but it doesn't actually tell you how to
do it.
I guess i need to write something like
if DBEdit1.Datasource.Dataset.AfterScroll then
    set the TDateTimePicker.value :=
DBEdit1.Datasource.Dataset.FieldByName('Date').AsDate;
I know this is not correct, so i am hoping someone could give me some clues.

If someone could help with this i would be very grateful

John Shobbrook

 

Re:Can i get help on writing an afterscroll event


One option is to place a TDataSource on the form and update the
DateTimePicker from within the OnDataChange eventhandler of the DataSource.

=Bill

Re:Can i get help on writing an afterscroll event


Yes, that's something i hadn't thought about. It does seem the simplest way.
However, wouldn't that event fire when the user is entering either a new
record or editing an existing one.
I suppose i would have to check that the TTable is in dsBrowse mode first.

I am still interested in how to setup an afterscroll event though.
Could you give me a few tips, or point me some some relevant code snippet ?

Thanks very much for the quick response anyway Bill

John

Re:Can i get help on writing an afterscroll event


Quote
"John" <john.shobbr...@btinternet.com> wrote in message

news:3b49f7c3$1_1@dnews...
Quote
> I am still interested in how to setup an afterscroll event though.
> Could you give me a few tips, or point me some some relevant code

snippet ?

Make a method of your form:
procedure TableAfterScroll(DataSet: TDataSet);

then in your form's OnActivate event:
DataModule.Table.AfterScroll := TableAfterScroll;

in your form's OnDeactivate event:
DataModule.Table.AfterScroll := nil;

But I think the best option is still to hande DataSource data change,
like Bill said.

--
Antony Hoon
Delphi {*word*60}ed
(Replace 4x7 with 7777 to reply..)

Quote

Re:Can i get help on writing an afterscroll event


So you are just linking the After scroll call from the datamodule to the new
TableAfterScroll event on the new form. Very cool.
I think i will go with the OnChange event of the datasource, like you both
suggested, but at least i have learnt another great technique along the way.
Thanks to you both
John

Quote
Antony Hoon <antony...@telkom.net> wrote in message

news:3b4a13cb$2_2@dnews...
Quote
> "John" <john.shobbr...@btinternet.com> wrote in message
> news:3b49f7c3$1_1@dnews...
> > I am still interested in how to setup an afterscroll event though.
> > Could you give me a few tips, or point me some some relevant code
> snippet ?

> Make a method of your form:
> procedure TableAfterScroll(DataSet: TDataSet);

> then in your form's OnActivate event:
> DataModule.Table.AfterScroll := TableAfterScroll;

> in your form's OnDeactivate event:
> DataModule.Table.AfterScroll := nil;

> But I think the best option is still to hande DataSource data change,
> like Bill said.

> --
> Antony Hoon
> Delphi {*word*60}ed
> (Replace 4x7 with 7777 to reply..)

Other Threads