<< Click to Display Table of Contents >> Navigation: Programming > Mail Merge (replace fields with data) and data forms > Forms & Edit Fields (data forms) > Create Fields |
To create a field use procedure
InputEditField(const FieldName: string;
DisplayText: string = '';
PlaceCaret: Boolean = FALSE;
Command: string = ''; // will be written to TWPTextObj.Source
Format: Integer = 0 // will be written to TWPTextObj.IParam
): TWPTextObj;
It is also possible to check the data the user types into an edit field. The event OnEditFieldCheckInputString can be used for this. It is only triggered if the protection was not disabled and the flag ppAllExceptForEditFields was used in ProtectedProp.
In his example we use the event to let the user toggle a checkbox value with the space key and to restrict the count of characters in a field to 30.
procedure TWPEdTest.DataEditEditFieldCheckInputString(Sender: TObject;
field: TWPTextObj; var text: string; var abort: Boolean);
var embedded : TWPTextObj;
begin
if field.NameIs('_check') then
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
Abort := (text <>#8) and (text<>#127) and not
(Sender as TWPRTFEngineEdit).Cursor.IsSelected(true) and
(Length(field.EmbeddedText)>30);
end;
Note: WPGetCheckBoxValue(embedded,true) does not trigger an exception of no checkbox was found and will return false in this case.