Reputation: 1368
I have created a custom Styledcontrol descendant, that consist out of 3 TEdit's that represent a date (Day/month/hour), the Edits are part of my .style file
When the control gets focus, the first Edit should get focus. the other edits should never get focus through tabbing. they have tabstop = false in the style file.
constructor TPWCalendar.Create(AOwner: TComponent);
Oncanfocus:=FocusEdit;
procedure TPWCalendar.FocusEdit(Sender: TObject; var ACanFocus: Boolean);
begin
ACanFocus:=false;
if Findedits then
if not FDayEdit.isfocused then
FDayEdit.SetFocus;
end;
This works, but when one of the children Edits is focused, and i press tab, the first edit of the first created custom control is selected. How to make it have default behaviour and select the next control as if it was 1 control? (So no matter where the focus lies in the control - edit1, edit2 or edit3, pressing tab should select the next control).
PS: Is there any decent firemonkey component tutorial? considering styling etc.
I have updated the question
Upvotes: 2
Views: 3097
Reputation: 1368
I have solved the main problem.
By setting a private oncanfocusEvent, the first child (FDayEdit) is selected. Then i overwrite DialogKey, when one of my childs is focused, the main component gets focus (note that this triggers the oncanfocusevent). then default behaviour is called with inherrited.
thnx slomoto for showing me in the right direction.
PS: FindEdits assigns the Edits from the styleresource,and returns false if failed.
This is the oncanfocusEvent:
procedure TPWCalendar.FocusEdit(Sender: TObject; var ACanFocus: Boolean);
begin
if findedits and ( fDayEdit.IsFocused or FMonthEdit.IsFocused or FYearEdit.IsFocused)
then aCanFocus:=true
else begin
ACanFocus:=false;
if Findedits then
FDayEdit.SetFocus;
end;
end;
Then This is the DialogKey Event
procedure TPWCalendar.DialogKey(var Key: Word; Shift: TShiftState);
begin
if key=vktab then
if ischildfocused then begin
self.SetFocus;
inherited;
end;
end;
Upvotes: 0