Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

Modal form interaction

Hi, I'm making a color dialog component and have a form with a tshape on it. When the user presses a button another form (dialog component) opens modally. In the new modal form's onmousemove event I have code which gets the color at the desired point and then it should set the tshape's color with that one. But the color dosen't get set while the mouse is moving over the modal (dialog) form, it gets set when the form closes. How can I pass the color to the main form while the mouse is moving over the modal one?

Thanks
0
Bindza
Asked:
Bindza
  • 6
  • 3
  • 3
  • +3
1 Solution
 
esoftbgCommented:
I tested with the next code:
Form1 contains Shape1 colored in clWindow
Form2 contains Memo1 colored in clMoneyGreen and is Showed as a Modal Form by Form1 ....

procedure TForm2.Memo1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  Form1.Shape1.Brush.Color := Memo1.Color;
//  Application.ProcessMessages;
end;

It works fine and does not need to call Application.ProcessMessages to force Paint the new Color;
0
 
vadim_tiCommented:
you can try

  Form1.Shape1.Brush.Color := Memo1.Color;
  Form1.Shape1.Refresh;
0
 
BindzaAuthor Commented:
This can't be done:

procedure TForm2.Memo1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  Form1.Shape1.Brush.Color := Memo1.Color;
//  Application.ProcessMessages;
end

Theres no way I can call Form1.something from Form2. Form2 is dialog box component (shown modally) and form1 is the main form the component was dropped on. I proved an event in form2 - OnColorChange which is fired in OnMouseDown, but it doesn't get called until the modal form is closed. Strangely, if I put Showmessage('xxx') in the OnColorChange event - it shows the message when the mouse is moved.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
esoftbgCommented:
Try this:

procedure TForm2.Memo1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
  I:      Integer;
begin
  with Application.MainForm do
    for I := 0 to ComponentCount-1 do
    if (Components[I].Name ='Shape1') then
      if (Components[I].ClassType = TShape) then
      begin
        TShape(Components[I]).Brush.Color := Memo1.Color; // Here will be not Memo1.Color, but the Color you have
        Break;
      end;
end;
0
 
BindzaAuthor Commented:
Come on, you know that the form calling a dialog to apper doesn't always have to be the main form, and the component name doesn't have to be shape1 (it even doesn't have to be TShape at all). THIS IS A DIALOG BOX COMPONENT, SO THE FORM THAT IS SHOWN MODALLY HAS TO WORK IN ALL CASES WITH ALL KINDS OF COMPONENTS. So, how do I get the event to fire while the mouse is moving over the modal form. When the event fires I can do whatever I want with the main form, but the event doesn't fire until the modal form is closed...
0
 
esoftbgCommented:
Oooops, you develop a component .... Excuse me .... My mistake, I consider a modal Form as a part of an Application ....
0
 
doporsCommented:
Here is My Code;

--dpr--
program Color1;

uses
  Forms,
  MainForm in 'MainForm.pas' {Form1},
  fForm2 in 'fForm2.pas' {Form2};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.



--- Main Form ---
unit MainForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, fForm2;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure ColorMainForm(var Msg: TMessage); message CL_FORM;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Assigned(Form2) then
    Application.CreateForm(TForm2,Form2);
  with Form2 do begin
    FormHandle := Form1;
    ShowModal;
  end;
end;

procedure TForm1.ColorMainForm(var Msg: TMessage);
begin
  Self.Color := Msg.WParam;
end;

end.

--------- Holds the Simple Color Pallete of Shape ----
unit fForm2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

Const
  CL_FORM = WM_USER + 1;

type
  TForm2 = class(TForm)
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
    Shape4: TShape;
    Shape5: TShape;
    procedure Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
    FHandle: TComponent;
    procedure SetHandle(const Value: TComponent);
  public
    { Public declarations }
    property FormHandle: TComponent write SetHandle;
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.SetHandle(const Value: TComponent);
begin
  FHandle := Value;
end;

procedure TForm2.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  FColor: TColor;
begin
  //Lets Say that 1 = YELLOW and 2 = BLUE;
  //I used the WParam to send the Color value to the caller form
  SendMessage(TWinControl(FHandle).Handle, CL_FORM, TShape(Sender).Brush.Color, 0);
end;

end.



0
 
doporsCommented:
btw on the Form 2 change the color of each TShape Component to the color you like.
0
 
Stuart_JohnsonCommented:
Bindza,

What I'd do is publish a new event from the component (OnColourSelect maybe).  Add code in there to respond to colour changes:

procedure TForm1.MyColourComponentColourChange(Sender: TObject; NewColour: TColor);
begin
  Edit1.Color := NewColour;
end;

Each time you clicked on your TShape, you'd also called the ColourChange procedure within the component.

If you need an example, I can probably do one (bit pressed for time).  But this is really easy.  It'll definately do what you want.

Stu
0
 
BindzaAuthor Commented:
I'll try all of that as soon as I can. I've been reinstalling Windows and all programs, so I need a little time to set it all up...
0
 
BindzaAuthor Commented:
I still haven't installed all the components and set up delphi, but I can say that the code ^ "up there" can't solve my problem. I accidently deleted some of my work when I formatted the hdd, but I managed to dig up a part of it. If you give me your e-mail(s) I can post you the source (2,55KB), so you can see what it's really about...
0
 
Stuart_JohnsonCommented:
Hi Bindza,

Send it onto necrostu@gmail.com

Cheers.

Stuart.
0
 
BindzaAuthor Commented:
Sent...
0
 
BindzaAuthor Commented:
A friend helped me solve this. Since I used Brush.Style := bsClear (as recomended in one of the tips or tutorials here on delphi.about) the color change on the parent form could not be seen. The minute I changed the alpha blend value to 50 and turned on blending I could see the colors changing in real time. It wasn't about form interaction, but form transparency...
0
 
Stuart_JohnsonCommented:
Ah.  That'll do it every time :)

Why don't you just change the Brush Style to bsSolid?


Stuart.
0
 
ee_ai_constructCommented:
Question answered by asker or dialog valuable.
Closed, 250 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now