BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OldValue returns NewValue in TField OnValidate

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Multi-Tier)
View previous topic :: View next topic  
Author Message
Roger Graham
Guest





PostPosted: Sat Jul 05, 2003 3:34 pm    Post subject: OldValue returns NewValue in TField OnValidate Reply with quote



I have validation in a TClientDataSet TField OnValidate. This checks that
we are not changing a date field from or to a unallowed date.

If there is an error, I want to change the field back to the old value. The
help says

For example, the following line replaces current pending changes with a
field's original value:

NewValue := OldValue;

However, in the OnValidate event OldValue returns the newly entered value,
so I cannot validate the original value in the field.

If I move the event handler to the OnChange, then OldValue does return the
original value in the field, but setting NewValue to OldValue causes an
Access Violation in unit DB.

TDataSet.SetStateFieldValue

Field.AsVariant := Value;

If I set TFieldValue to OldValue, the DBEdit does not update unless the user
presses the Esc key.

The field is a date field and the locale is UK, i.e. dd/mm/yyyy.

How do I validate a TField and reset its value if invalid?

--
Regards

Roger Graham
Designkey Ltd


Back to top
Jim Poe
Guest





PostPosted: Mon Jul 07, 2003 4:55 pm    Post subject: Re: OldValue returns NewValue in TField OnValidate Reply with quote



Roger Graham wrote:

Quote:

How do I validate a TField and reset its value if invalid?


Raise an exception or call Abort.

Back to top
Roger Graham
Guest





PostPosted: Mon Jul 07, 2003 8:15 pm    Post subject: Re: OldValue returns NewValue in TField OnValidate Reply with quote



Quote:
How do I validate a TField and reset its value if invalid?


Raise an exception or call Abort.

Doesn't work, new invalid value stays in field.

Even curiouser, on Inserting a new record, the OldValue in OnChange returns
the value in the record active before the insert, not null as I would
expect.

Regards

Roger Graham



Back to top
Dave Rowntree
Guest





PostPosted: Mon Jul 07, 2003 9:35 pm    Post subject: Re: OldValue returns NewValue in TField OnValidate Reply with quote

"Roger Graham" <rgraham (AT) designkey (DOT) co.uk> wrote:

Quote:
I have validation in a TClientDataSet TField OnValidate. This checks that
we are not changing a date field from or to a unallowed date.

If there is an error, I want to change the field back to the old value. The
help says

For example, the following line replaces current pending changes with a
field's original value:

NewValue := OldValue;

However, in the OnValidate event OldValue returns the newly entered value,
so I cannot validate the original value in the field.

OldValue is not available in the TField.OnValidate event.

Quote:
If I move the event handler to the OnChange, then OldValue does return the
original value in the field, but setting NewValue to OldValue causes an
Access Violation in unit DB.


In TField.OnChange you could put:

if Sender.Value <> Sender.OldValue then
Sender.Value := Sender.OldValue;

Quote:
How do I validate a TField and reset its value if invalid?

To access Sender.OldValue in a TField.OnValidate event you could use:

procedure TForm1.ClientDataSet1DetailsValidate(Sender: TField);
var
cdsClone: TClientDataSet;
begin
cdsClone := TClientDataSet.Create(nil);
try
cdsClone.CloneCursor((Sender.DataSet as TClientDataSet), False);
cdsClone.FieldByName(Sender.FieldName).Value; // returns
Sender.OldValue
Sender.Value; // returns the Sender proposed new value
finally
cdsClone.Free;
end;
end;


--
Dave Rowntree

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Multi-Tier) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.