Recent

Author Topic: [SOLVED]Send an Element to function ?!?  (Read 8616 times)

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: Send an Element to function ?!?
« Reply #15 on: May 21, 2017, 06:01:51 pm »
Quote
procedure DisableControls(Btn1, Btn2: TButton; Edit: TEdit);

can i use like this code :
Code: Pascal  [Select][+][-]
  1. procedure DisableControls([color=red]^[/color]Btn1, [color=red]^[/color]Btn2;[color=red]^[/color] Edit);
  2. begin
  3.       ^Btn1.caption := 'test';
  4. end;
  5.  

if yes , how?
.
this code isn't True and i just write for solution?!?!?

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: Send an Element to function ?!?
« Reply #16 on: May 21, 2017, 06:04:28 pm »
Did you mean you want to change the button's text color?

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: Send an Element to function ?!?
« Reply #17 on: May 21, 2017, 06:09:06 pm »
yes
it is sample
i want to change Visible and Enable and caption and ..... property of elements

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: Send an Element to function ?!?
« Reply #18 on: May 21, 2017, 06:13:22 pm »
Have you seen or tried my code?

You can change anything of the TButton and TEdit, including color. You should tried it before you ask.  >:(

But if you meant you want to change the color based on a parameter passed to the function, yes you can. You just have to add and pass the parameter.

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: Send an Element to function ?!?
« Reply #19 on: May 21, 2017, 06:15:16 pm »
To change button's text color:

Code: Pascal  [Select][+][-]
  1.   Btn1.Font.Color := clRed;

I saw you use this symbol: ^
Don't use it, this is wrong:

Code: Pascal  [Select][+][-]
  1.   ^Btn1.Font.Color := clRed;

It seems you have not fully understand how to use pointer, @ and ^. You need to read the documentation and do more practices.
 ;D
« Last Edit: May 21, 2017, 06:23:49 pm by Handoko »

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: Send an Element to function ?!?
« Reply #20 on: May 21, 2017, 06:54:49 pm »
thank you very much.
.
i think , i cann't explain my question! :'(

M+AUDIO

  • New Member
  • *
  • Posts: 48
Re: Send an Element to function ?!?
« Reply #21 on: May 21, 2017, 10:29:54 pm »
Quote
procedure DisableControls(Btn1, Btn2: TButton; Edit: TEdit);

can i use like this code :
Code: Pascal  [Select][+][-]
  1. procedure DisableControls([color=red]^[/color]Btn1, [color=red]^[/color]Btn2;[color=red]^[/color] Edit);
  2. begin
  3.       ^Btn1.caption := 'test';
  4. end;
  5.  

if yes , how?
.
this code isn't True and i just write for solution?!?!?

Hi,

If by using ^ symbol you mean using "pointer to those controls",  like Handoko mentioned, It's not necessary, Those controls you send as parameters are already pointers.

Hmmm, Do you want some smart procedure you can just pass (Control: TComponent; APropertyName, APropertyValue: String) ?? So you can pass any property of the control and it automatically finds out what are you talking about?
« Last Edit: May 21, 2017, 10:32:14 pm by M+AUDIO »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Send an Element to function ?!?
« Reply #22 on: May 21, 2017, 11:22:42 pm »
I cann't explain my question! :'(

I may not understand what you want at all. But it may also be that a "function" is not exactly what you want anyway.
The attached example project mimics your panels to a degree, and makes a TCustomPanel the container for a simple custom control whose public fields give you direct access to the properties you want to alter.
There is a main testing form which exercises some text-editing functionality on the custom control to give you some ideas.

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: Send an Element to function ?!?
« Reply #23 on: May 22, 2017, 02:29:09 pm »
Quote
Those controls you send as parameters are already pointers.

Thank you.
i think , it is my answer. :D :) ;D

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: Send an Element to function ?!?
« Reply #24 on: September 30, 2017, 05:49:19 pm »
thank you very much.
.
i think , i cann't explain my question! :'(

Hi

i have problem now!!?!?

i have 5 button and onClick event is  :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   ShowMessage((Sender as TButton).Caption);
  4. end;
  5.  

and i have 1 spinedit and 1 button again :

last button onClick event is :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button6Click(Sender: TObject);
  2. begin
  3.   with(Form1.FindComponent('Button'+IntToStr(SpinEdit1.Value)))do begin
  4.       Button1Click( ??? );
  5.     // .... My Code .....
  6.   end;
  7. end;
  8.  

what do i write in "???"   ?

if i write this code , it work :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button6Click(Sender: TObject);
  2. begin
  3.   with(Form1.FindComponent('Button'+IntToStr(SpinEdit1.Value)))do begin
  4.     Button1Click(Form1.FindComponent('Button'+IntToStr(SpinEdit1.Value)));
  5.     // .... My Code .....
  6.   end;
  7. end;
  8.  

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: [SOLVED]Send an Element to function ?!?
« Reply #25 on: September 30, 2017, 06:15:53 pm »
I tested your qqq, it works. Not sure what you want, but I recommend you to change to Button6Click to:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button6Click(Sender: TObject);
  2. var
  3.   Component: TComponent;
  4.   SelectedButton: TButton absolute Component;
  5. begin
  6.   Component := Form1.FindComponent('Button'+IntToStr(SpinEdit1.Value));
  7.   if not(Component is TButton) then Exit;
  8.   SelectedButton.Click;
  9. end;

Alternatively, you can change the line #8 to:
Button1Click(Component);
« Last Edit: September 30, 2017, 06:22:52 pm by Handoko »

 

TinyPortal © 2005-2018