<< Click to Display Table of Contents >> Navigation: Programming > Mail Merge (replace fields with data) and data forms > Forms & Edit Fields (data forms) > Validate Input |
To validate the input to a field, it is possible to use the event OnEditFieldCheckInputString
In this example we take care that the user cannot enter data into a checkbox field. All other fields are restricted to 30 characters
procedure TWPEdTest.DataEditEditFieldCheckInputString(Sender: TObject;
field: TWPTextObj; var text: string; var abort: Boolean);
var embedded : TWPTextObj;
begin
if field.NameIs('_check') then // we expect a boolean field
begin
if text=#32 then
begin
embedded := field.GetContainedObject([wpobjTextObject]);
if embedded<>nil then
begin
WPSetCheckBoxValue(embedded,not WPGetCheckBoxValue(embedded,true));
(Sender as TWPRTFEngineEdit).Repaint;
end;
end;
abort := true;
end
else // in any other field limit data entry to 30 characters
Abort := (text <>#8) and (text<>#127) and not
(Sender as TWPRTFEngineEdit).Cursor.IsSelected(true) and
(field.EmbeddedTextLength>30);
end;