Tell me how to combine the two procedures or convert one procedure into a function so that from the first procedure (function) pass the value to the second.

Function TForm1.Button1Click(Sender: TObject); var a , b : string; i : integer; begin a := Edit1.Text; b := Edit2.Text; i := Pos (b, a); ShowMessage(IntToStr(i)); end; procedure TForm1.Button2Click(Sender: TObject); var a : string; caunt : integer; begin a := Edit1.Text; caunt := Length(a); Delete (a, 5, caunt); ShowMessage (a); end; 

I need to insert the variable i from the first procedure into the second procedure Delete (a, 5, caunt); instead of "5" .

Screen:

alt text

  • @Klonny learn to begin with the theory of procedures and functions. This is the foundation of the language. - kot-da-vinci

2 answers 2

Maybe so:

 Function MyFunc(a, b: string): integer; Begin Result:= Pos(b, a); End; 

Then the call will be like this:

 ... Delete (a, MyFunc(Edit1.Text, Edit2.Text), caunt); ... 

And if you get rid of calling your function, you can:

 ... Delete (a, Pos(Edit2.Text, Edit1.Text), caunt); ... 

    Or just make I a global variable and calmly use it in the second procedure without frills)