Recent

Author Topic: Procedure call ?  (Read 8788 times)

thaimann

  • Jr. Member
  • **
  • Posts: 84
Procedure call ?
« on: May 08, 2005, 05:52:01 pm »
How do I write a procedure to modify the contents of a form's objects?

I currently have 2 procedures:

procedure TObjectForm.ObjectFormActivate(Sender: TObject);
begin
     ObjIdxEdit.Text    := ObjectTable.FieldByName('ObjIdx').AsString;
End

procedure TObjectForm.DBNavigator1Click(Sender: TObject;
  Button: TDBNavButtonType);
begin
     ObjIdxEdit.Text    := ObjectTable.FieldByName('ObjIdx').AsString;
End;

Since they are both doing the same thing, I would like to call a procedure in each.  Note iin my program, each of the original procedues doesn't have one duplicate instruction, but 20+!

What I tried to do was

A.  Declare a procedure in the type section
     Procedure ScrFldUpdate(Sender:   TObject);
B. Create the procedure
    Procedure TObjectForm.ScrFldUpdate(Sender:   TObject);
    Begin
     ObjIdxEdit.Text    := ObjectTable.FieldByName('ObjIdx').AsString;
    End;
C  Call this procedure from each of my previous procedures
   TObjectForm.ScrFldUpdate(Sender);

I got the following error msg:
   Error:   Only class methods can be referred with class references


Thx,   Terry

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Procedure call ?
« Reply #1 on: May 08, 2005, 07:55:03 pm »
Quote
C Call this procedure from each of my previous procedures
TObjectForm.ScrFldUpdate(Sender);


Use
Code: [Select]
 ScrFldUpdate(Sender);

or
Code: [Select]
 Self.ScrFldUpdate(Sender);


Since you don't use Sender in this example, you could choose to remove the Sender parameter of SrcFldUpdate.

 

TinyPortal © 2005-2018