1 (edited by thezimguy 2018-12-27 16:05:02)

Topic: One procedure for all Forms

Hello Dmitry,
Please how do I make this procedure work?

I have two forms (Form1 & Form2) and a button each (Button1) on each form.
I want this procedure to work for any form. Thus i want to reference any form and its controls in the procedure.

procedure callComponents(Form: TAForm);
begin
    Form.Button1.Caption:='Clicked';
end;

procedure Form1_Button1_OnClick (Sender: String; var Cancel: boolean);
begin
    callComponents(Form1);
end;

procedure Form2_Button1_OnClick (Sender: String; var Cancel: boolean);
begin
    callComponents(Form2);
end;

Thank you.

@thezimguy

Re: One procedure for all Forms

TdbButton(Form.FindComponent('Button1')).caption:='Clicked';

Re: One procedure for all Forms

Thank you all.
Really appreciated

@thezimguy

Re: One procedure for all Forms

sibprogsistem wrote:
TdbButton(Form.FindComponent('Button1')).caption:='Clicked';

Exactly what I needed.

@thezimguy

5 (edited by thezimguy 2019-01-03 00:01:36)

Re: One procedure for all Forms

Hello sibprogsistem,

Again, please see if you can help me with this

procedure callForm(Form: TAForm);
begin
    TdbEdit(Form.FindComponent('Edit1')).Text :='Worked';
end;

procedure Form1_Button1_OnClick (Sender: String; var Cancel: boolean);
begin
    callForm(TAForm(TControl(Sender).Parent))
end;

Details
............................
The project has a form(Form1), button (Button1), panel(Panel1) and Edit(Edit1)

The above code worked perfectly without a problem when the button is placed on the form but does not work when the button is inside the panel.
What I want is to get the parent of the button which is the form but not the panel.
Thank you

@thezimguy

Re: One procedure for all Forms

Thank you
I have been able to figure it out.

procedure callForm(Form: TAForm);
begin
    TdbEdit(Form.FindComponent('Edit1')).Text :='Worked';
end;

procedure Form1_Button1_OnClick (Sender: String; var Cancel: boolean);
begin
    callForm(TAForm(TControl(Sender).Owner))
end;

I just had to change the Parent to Owner

@thezimguy