I have a problem with showing a modal form from a custom component. During the application start the CustomComponent creates a custom form (CreateMenu) which is not visible for the user. When the user clicks on the component (during runtime) the custom form is shown (MouseClick) which is a form with buttons - commands.
When I use ShowModal method to show the menu-form for the component The Parent form is blocked and also the shown menu-form is blocked. Below is the code for creating the custom form (in a custom component) and showing it.
procedure TCustomComponent.MouseClick(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X: integer; Y: integer);
begin
self.Repaint;
self.PMenuForm.Left := self.Left; // p.x;
self.PMenuForm.Top := self.Top + self.Height + 5; // p.Y+self.Height+5;
PMenuForm.ShowModal;
end;
procedure TCustomComponent.CreateMenu(title: string);
begin
if PMenuForm = nil then
begin
PMenuForm := TForm.Create(self.Parent);
PMenuForm.Parent := self.Parent;
PMenuForm.ParentWindow := self.Parent.Handle;
PMenuForm.FormStyle := fsStayOnTop;
PMenuForm.Enabled := true;
PMenuForm.Visible := false;
PMenuForm.BorderWidth := 2;
PMenuForm.BorderStyle := bsNone;
PMenuForm.BorderIcons := [];
PMenuForm.caption := title;
PMenuFormTitle := TLabel.Create(PMenuForm);
PMenuFormTitle.Left := 0;
PMenuFormTitle.Top := 0;
PMenuFormTitle.Margins.Left := 5;
PMenuFormTitle.AutoSize := true;
PMenuFormTitle.Visible := true;
PMenuFormTitle.Parent := PMenuForm;
PMenuFormTitle.Font.Color := MakeColor($FFFFFF);
PMenuFormTitle.Font.Size := 10;
PMenuFormTitle.Font.Style := [fsBold];
PMenuFormTitle.Color := MakeColor($0000CC);
PMenuFormTitle.Transparent := false;
PMenuFormTitle.caption := title;
PMenuFormTitle.Layout := tlCenter;
PMenuFormTitle.Alignment := taLeftJustify;
PMenuFormTitle.AutoSize := false;
if PMenuFormTitle.Width < 55 then
PMenuFormTitle.Width := 65;
if PMenuFormTitle.Height < 10 then
PMenuFormTitle.Width := 10;
PMenuFormItems[0] := TBitBtn.Create(PMenuForm);
PMenuFormItems[0].Parent := PMenuForm;
PMenuFormItems[0].ParentWindow := PMenuForm.ClientHandle;
PMenuFormItems[0].tag := 0;
PMenuFormItems[0].Enabled := true;
PMenuFormItems[0].Visible := true;
PMenuFormItems[0].Top := 0;
PMenuFormItems[0].Left := PMenuFormTitle.Width - 22;
PMenuFormItems[0].caption := 'X';
PMenuFormItems[0].Font.Style := [fsBold];
PMenuFormItems[0].Width := 20;
PMenuFormItems[0].Height := PMenuFormTitle.Height;
PMenuFormItems[0].OnClick := self.MenuItemClick;
PMenuForm.AutoSize := true;
self.PMenuFormItemsCount := 0;
self.OnMouseDown := self.MouseClick;
self.Cursor := crHandPoint;
end;
end;
Thank you for any suggestions.
Clarifications: 1. Blocked means that the parent form AND the shown menu-form are both unresponsive, not enabled. Also every button on the menu-form is unresponsive ie. does not respond to mouse hoover, and cannot be clicked (it is not grayed though just does not react to clicks and anything else)
- It is intended that the parent form is "blocked" / unresponsive but this also affects the shown menu-form - it is also unresponsive (buttons it).