Recent

Author Topic: How to write a procedure correctly  (Read 413 times)

CarmichaelJohn

  • New Member
  • *
  • Posts: 38
How to write a procedure correctly
« on: November 19, 2020, 06:43:20 am »
Hello,

I have not done this particular thing before and although it must be simple, I am having a very difficult time figuring out what I am doing wrong.  My problem is that I have coded two procedures, to input two large matrices so that I can multiply them.  I have always written a procedure as procedure “procedure name.” then followed by “(Sender: TObject);” at the very end of that line of code. Now when I tried to call the procedure within another procedure, I get the error messages:
      “Error: wrong number of parameters specified for call to “GetMatrixAelements”.

   I have attached a zipped file of the program.

   I would appreciate any help or suggestions that anyone might have.  Thank you.
John

egsuh

  • Hero Member
  • *****
  • Posts: 505
Re: How to write a procedure correctly
« Reply #1 on: November 19, 2020, 07:00:37 am »
Pass nil as a parameter.

Code: Pascal  [Select][+][-]
  1.    GetMatrixAelements(nil);
  2.  

But you don't have to do that. Define your procedures within private or public sector.

Code: Pascal  [Select][+][-]
  1.   TFormMainProgramMatrixManipNov112020 = class(TForm)
  2.     // Here's PUBLISHED section
  3.     Button1: TButton;
  4.     // .............................
  5.     MenuItem9: TMenuItem;
  6.  
  7.     procedure FormCreate(Sender: TObject);
  8.     procedure MenuItem5Click(Sender: TObject);
  9.   private
  10.     // if other units that uses this unit do not need following procedures, put them in private sector.
  11.      procedure GetMatrixAelements;
  12.      Procedure GetMatrixBelements;
  13.  
  14.   public
  15.     // Define a procedure / function that should be open to other untis here. You don't need (Sender:TObject)
  16.      procedure MultiplyMatrixAxMatrixB;
  17.  end;

Components or methods in the published sector are to access their properties from object inspector.
« Last Edit: November 19, 2020, 07:04:00 am by egsuh »

speter

  • New Member
  • *
  • Posts: 42
Re: How to write a procedure correctly
« Reply #2 on: November 19, 2020, 07:04:26 am »
John,

My first suggestion is to get rid of the million and one edit boxes!!

I would suggest having 3 memos (or maybe stringgrids).

Using memos, the user should be able paste a matrix (with numbers separated by coma, semi-colons or tabs) into each.

I'd include a button - for the user to hit after they've pasted the data into the memos. I am assuming Matrix C is for the output data. Your program can read through the data in the memo's and parse the information and add the numbers into the matrix arrays.

cheers
S.

CarmichaelJohn

  • New Member
  • *
  • Posts: 38
Re: How to write a procedure correctly
« Reply #3 on: November 19, 2020, 09:01:30 pm »
Egsuh,
Thank  you, that worked well.  I also learned that to define a procedure then to use that procedure within another procedure in the same form, one must list it in the private or public parts of the structure.  Thank you, I am learning.
John

Bart

  • Hero Member
  • *****
  • Posts: 4040
    • Bart en Mariska's Webstek
Re: How to write a procedure correctly
« Reply #4 on: November 19, 2020, 09:07:37 pm »
My first suggestion is to get rid of the million and one edit boxes!!

I would suggest having 3 memos (or maybe stringgrids).

Since you seem to want the user to manually enter data: use a TStringGrid.
If you have the data as CSV values, you can use LoadFromCSVFile, if you have it as HTML on the clipboard, you can paste it in the stringgrid.

Just drop a TStringGrid on the form and set ColCount and RowCount to the derised values.
Bart

Bart

  • Hero Member
  • *****
  • Posts: 4040
    • Bart en Mariska's Webstek
Re: How to write a procedure correctly
« Reply #5 on: November 19, 2020, 09:12:42 pm »
I have always written a procedure as procedure “procedure name.” then followed by “(Sender: TObject);”

The (Sender: TObject) is for events.
The Sender is the TObject derived class that triggers the event.

E.g.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1.Click(Sender: TObject);
  2. begin
  3.   //If you click on Button1, it will trigger this event. Sender will be Button1 in that case
  4.   //we set the button's caption
  5.   if (Sender is TButton) then TButton(Sender).Caption := 'You clicked me';
  6. end;

Bart

speter

  • New Member
  • *
  • Posts: 42
Re: How to write a procedure correctly
« Reply #6 on: November 20, 2020, 06:44:10 am »
In case you are interested, I've put together a simple application to do matrix concatenation. I am using very simple matrixes; but the project does show "parsing" a coma-delim file.

If I get the chance, I'll put together a similar project using TStringgrid.

NOTE: This app is set as 1500px wide, so it could cause problems on low-res displays.

cheers
S.

speter

  • New Member
  • *
  • Posts: 42
Re: How to write a procedure correctly
« Reply #7 on: November 20, 2020, 08:13:25 am »
I've attached a simple matrix concat. application to this post.
It uses TStringGrid.
While it may not pretty, it seems to work. :)

cheers
S.

 

TinyPortal © 2005-2018