Recent

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

zzamyy

  • New Member
  • *
  • Posts: 10
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: 3025
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.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

zzamyy

  • New Member
  • *
  • Posts: 10
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

  • Sr. Member
  • ****
  • Posts: 408
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: 331
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: 2132
  • 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

  • New Member
  • *
  • Posts: 10
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

  • New Member
  • *
  • Posts: 10
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #7 on: April 02, 2020, 02:18:55 am »
HELP! :o

eljo

  • Sr. Member
  • ****
  • Posts: 408
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #8 on: April 02, 2020, 03:39:35 am »
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: 436
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #9 on: April 02, 2020, 03:48:57 am »
I don't understand what you are trying to do.  In most cases you don't have to use TMethod yourself. 

zzamyy

  • New Member
  • *
  • Posts: 10
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #10 on: April 02, 2020, 07:07:35 am »
help me real selfs

bytebites

  • Sr. Member
  • ****
  • Posts: 299
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #11 on: April 02, 2020, 08:06:43 am »
Code: Pascal  [Select][+][-]
  1. procedure ficha.listen_band(Sender:TObject);
  2. begin
  3.     showMessage('close your opinion '+ficha(TControl(sender).Parent).album_title.Caption);
  4. end;
  5.  

zzamyy

  • New Member
  • *
  • Posts: 10
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #12 on: April 03, 2020, 10:06:12 pm »
after so many modules i can NOT declare with is the most close to a solution. I carelesss

PascalDragon

  • Hero Member
  • *****
  • Posts: 2132
  • Compiler Developer
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #13 on: April 04, 2020, 10:57:07 am »
Please provide a full, complete example that shows what you're trying to do. Then and only then can we really help you.

jamie

  • Hero Member
  • *****
  • Posts: 3528
Re: One procedure for multiple(xxx) params, a call and a procede
« Reply #14 on: April 04, 2020, 03:06:26 pm »
I believe I see what he is trying to accomplish and lacks the understanding of how the Object model works
----
 It looks like he is attempting to define a Sender_ TMethod but is miss using the .Data section..

 Why he is doing this is beyond me since you can directly set it and the compiler will handle it

 The other way to look at it is that maybe he is attempting to repurpose the .DATA member of the TMethod.. ?

  I believe all he needs to do  in the case of repurposing the data member is to place a an INTEGER filed in the record area of the object where it will be defined to a simple value so that  later on when he can reference which record it is …

  for example
   ficha(sender_).TheIdentifier

 So it looks like he wants each object/Class field to be able to reference it self as well as referencing other instances of a certain type while in there.

A series of Sender_ as ??????? would most likely solve his issue..

 Like you said a clearer picture of his attempt is needed.




The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018