Re:Datamodule vs. datasources in forms
John Petersen <jo...@post1.tele.dk> wrote in article
<31F017F1.1...@post1.tele.dk>...
Quote
> Koh Yang Uei wrote:
> > >no knowledge about the form, or the fields on that form. I have work
> > >around, which basically loops through the components on the form,
looks for
> > >a TDBEdit (or whatever) with a fieldname property of the offending
field
> > >name.
> > can you kindly briefly explain how you loops through the componentns
> > on the form from the data module unit ?
> And why are you doing it anyway? Check out the FocusControl method of the
> TField component:
> "Declaration
> function FocusControl;
> Description
> Sets a form's focus to the first data-aware component associated with a
> TField. Use this method when doing record-oriented validation (for
example,
> in the BeforePost event) since a field may be validated whether its
> associated data-aware components have focus."
John :
Sure that will work if you are doing inline validation. Frankly, most
accounting products (which is what I am working on) do validation when
attempting to post a record. This is because some data is not valid based
upon criteria entered by the user. For instance, when posting a credit
memo, I can allow them to select the GL Account they are going to post the
adjustment to before selecting the invoice number it is going to. However,
when they click the "Post" event I need to see if they have a valid invoice
number, then if it is not valid (the adjustment date is before the invoice
date, no invoice number exists, many other problems) I need to set focus to
the field which is causing the error.
Koh :
Here is some sample code to scroll through the components on a form:
while ( I < ComponentCount ) AND ( bFound <> TRUE ) do begin
if ( Components[I] is TDBEdit ) AND (
TDBEdit(Components[I]).DataField = sFldName
) then begin
bFound := TRUE;
TDBEdit(Components[I]).SetFocus;
end; // if ... then begin
Inc(I);
end; // while ... do begin
Mike