Bookstore

Recent

Author Topic: One procedure for multiple(xxx) params, a call and a procede  (Read 518 times)

zzamyy

  • Newbie
  • Posts: 4
One procedure for multiple(xxx) params, a call and a procede
« on: March 05, 2020, 09:08:14 am »
So, read about a TMethod was a kind of hoper info.
but it not woik.
The program has an object  and is multiplied any time by some reason.
Code: Pascal  [Select]
  1. type
  2. ficha=object
  3. public
  4.   Panel_fuck: TPanel;
  5.   image:TImage;
  6.   listen:TButton;
  7.   name_item:TLabel;
  8.   album_title:TLabel;
  9.   artist_title:TLabel;
  10.   price_item:TLabel;
  11.   flag:TLabel;
  12.   sender_:TMethod;
  13.   url:String;
  14.   url_2:TLabel;
  15.   procedure listen_band(Self:Pointer; Sender:TObject);
  16. end;  

So call to the procede is not working. at less this method whit TMethod  :'(
Code: Pascal  [Select]
  1.  requiered_var.listen:=TButton.Create(nil);
  2.   requiered_var.listen.Parent:=requiered_var.Panel_fuck;
  3.   requiered_var.listen.Hint:=url;
  4.   requiered_var.listen.ShowHint:=True;
  5. requiered_var.sender_.Code:=@ficha.listen_band;
  6.  
  7.   requiered_var.url_2:=TLabel.Create(nil);
  8.   requiered_var.url_2.Parent:=requiered_var.Panel_fuck;
  9.   requiered_var.url_2.Visible:=False;
  10.   requiered_var.url_2.Caption:=requiered_var.url;
  11.  
  12.  
  13.   requiered_var.sender_.Data:= PInteger(2);
  14.   requiered_var.listen.OnClick:=TNotifyEvent(requiered_var.sender_);

Ok ;D is called but no Data (??)
So the procedures i rule in the next way:
Code: Pascal  [Select]
  1. procedure ficha.listen_band(Self:Pointer; Sender:TObject);
  2. begin
  3.     showMessage(Self);
  4. end;  

as is told not pass Data across the Pointer Called Self.
How to procede?

lucamar

  • Hero Member
  • *****
  • Posts: 2572
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #1 on: March 05, 2020, 11:47:31 am »
Maybe I'm missing what you're trying to do, but why are you (re-)declaring Self? The real Self is already passed as a hidden parameter to any of its methods, so all your new Self does is to hide the real instance reference.

The method declaration shoud be simply:
Code: Pascal  [Select]
  1.   procedure listen_band(Sender:TObject);
and you can refer to Self inside its definition without more ado.

Also, any reason why you're using an old-style object instead of a class?
« Last Edit: March 05, 2020, 11:51:45 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.6/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

zzamyy

  • Newbie
  • Posts: 4
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #2 on: March 05, 2020, 01:24:39 pm »
Lazarus is a good program to apply Pascal Lenguage and quickly realize a simple program but in this case not so good.
is just because. As a wokers this put a strange line bettwen delivery and money.
Is also a demostration. But it keeps to wait.
Any idea how to call the values from the procedure?

eljo

  • Full Member
  • ***
  • Posts: 159
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #3 on: March 05, 2020, 01:43:01 pm »
the data variable is not for you to access or set, it should always point to an existing object. You need to declare your own variables.

If you cared to explain what you are trying to accomplish there are people here that have the expertise to help do it.


devEric69

  • Sr. Member
  • ****
  • Posts: 254
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #4 on: March 05, 2020, 02:36:21 pm »
One important remark (already said): " Self " is your a Free Pascal reserved word. Self already - automatically - contains the instance of the object (like "this" in other languages) in which a method - like listen_band - is declared. So, Self is the created TForm's instance.

So it would be better to write:

Code: Pascal  [Select]
  1. procedure TForm.listen_band(Sender: TObject);
  2. var
  3.     i, j, k: integer;
  4. begin
  5.     i:= 2; j:= 3; k:= i + j;
  6.     showMessage('The total is ' + InToStr(k));
  7.     showMessage('The object name - TForm.name - is: ' + Self.name);
  8.     showMessage('The object calling this method, is of the type: ' + Sender.ClassName);
  9. end;  

ps: it would be better to post a short zipped example program, in order to understand, what you would like it must do.
« Last Edit: March 07, 2020, 09:25:29 am by devEric69 »
use: Linux 64 bits (Ubuntu 18.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

PascalDragon

  • Hero Member
  • *****
  • Posts: 1088
  • Compiler Developer
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #5 on: March 06, 2020, 09:53:54 am »
So the procedures i rule in the next way:
Code: Pascal  [Select]
  1. procedure ficha.listen_band(Self:Pointer; Sender:TObject);
  2. begin
  3.     showMessage(Self);
  4. end;  

as is told not pass Data across the Pointer Called Self.
How to procede?

Please note that listen_band is an instance method. Thus there already is a hidden Self parameter:

Code: Pascal  [Select]
  1. procedure ficha.listen_band(var $realself: ficha; Self:Pointer; Sender:TObject);
  2. begin
  3.     showMessage(Self);
  4. end;

So if you remove your Self: Pointer it might work already, however please not that it's not intended to use TMethod together with methods of type object. Use a class instead and don't use tricks like passing a constant value as Self. Sooner or later this will come back to bite you.

zzamyy

  • Newbie
  • Posts: 4
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #6 on: March 26, 2020, 04:11:03 am »
shoud
this the far far away is tried. and no working.
Code: Pascal  [Select]
  1. type
  2. ficha=class
  3. public
  4.   Panel_fuck: TPanel;
  5.   image:TImage;
  6.   listen:TButton;
  7.   name_item:TLabel;
  8.   album_title:TLabel;
  9.   artist_title:TLabel;
  10.   price_item:TLabel;
  11.   flag:TLabel;
  12.   sender_:TMethod;
  13.   url:String;
  14.   url_2:TLabel;
  15.   procedure listen_band(Sender:TObject);
  16. end;  

is class as is required not that object was not equals. that is not.

Code: Pascal  [Select]
  1. procedure ficha.listen_band(Sender:TObject);
  2. begin
  3.     showMessage('close your opinion'+ficha.ClassName);
  4. end;  
and this up is the far.

ficha is related whit the class but applie The Self is not in any wiki. How to procede to pointythe class that was created and the variables in self?

zzamyy

  • Newbie
  • Posts: 4
HELP! :o

eljo

  • Full Member
  • ***
  • Posts: 159
HELP! :o
create simple program to demonstrate the problem you are having. There is something wrong with your use people will be happy to explain what you seem to misunderstand.

egsuh

  • Sr. Member
  • ****
  • Posts: 316
I don't understand what you are trying to do.  In most cases you don't have to use TMethod yourself.