Hi people ,

I have an easy question(but lack the knowledge in Delphi),

I have a piece of code that i want to run but don't want to type it over for every time
it has to be run (not very good coding then). Is there a way i can place it in a procedure
or function and just call it every time(like a method).

An Example would be clearing a bunch of TEdit boxes at different button events or Naming Labels based on Grid columns?


#Note I'm working with Delphi 6

Recommended Answers

Just put it in a function/procedure and call it. Define it like this:

interface

TForm1 = class(TForm)
private
  procedure RepetitiveTask;
end;

implementation

procedure TForm1.RepetitiveTask;
begin
  // ...
end;
Jump to Post

All 2 Replies

Just put it in a function/procedure and call it. Define it like this:

interface

TForm1 = class(TForm)
private
  procedure RepetitiveTask;
end;

implementation

procedure TForm1.RepetitiveTask;
begin
  // ...
end;

Thanks pritaeas!
I managed to do it on my own , but in the same why you explain it here.
All I did different is add components.

procedure ClearEdits (a,b: TEdit);
begin
 a.Clear;
 b.Clear;
end;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.