Topic: Advice on cleaning up code
Hi All,
.
I could use some advice/opinions please. I have a form with an On-Show event that has a bunch of script I've written to address issues when I open and process the form. Over the past few months I have been adding a number of If statements to the script. These do all kinds of things that I felt I needed. On the plus side, the code works as written. On the negative side, in my opinion, it's messy and hard to work with. Even though I wrote it, with the excellent help from folks on the forum, I'm finding it's hard to understand, especially when I want to add or change some functionality. Please see the attached code.
.
My thought is maybe I could break it up into sup-procedures that I could call from within the script. I found this code from Dmitry that seems to suggest what I think I could do. However I can't seem to get it to work. And I'm not sure if this is even the best way to clean up my messy code?
// Call a procedure from within a prodedure
procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
procedure1;
end;
procedure procedure1;
begin
procedure2;
end;
procedure procedure2;
begin
ShowMessage('Hello from proc 2');
end;
.
Maybe I shouldn't be using so many If statements?
.
Right now, as I mentioned, the code is working so I'm hesitant to mess with it. But I would like to make it more user friendly (for me) if possible.
.
Thanks for your help.
Frank