"It was around 2005 when I landed my first job at a small software company," writes Derek, "I was the youngest programmer on the team by at least a decade, and my coworkers certainly made sure I remembered it. Fortunately, it was all in good fun, but they reminded me that I had a long way to go and that I should learn from older, more experienced folks – presumably like them."
"In the midst of 'learning' from them, I noticed that on many of the companies projects used the same pattern where the main window five different buttons and three stock photos. Each button had a glow that appeared on hover and the first three buttons would trigger a corresponding stock photo to display. Nothing too crazy, though this hi-tech feature took my predecessor astonishing 280 lines of code… in each project it was implemented in."
var semafor_pic1, semafor_pic2, semafor_pic3, semafor_pic4, semafor_pic5 : boolean; procedure TForm1.Image2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if semafor_pic1 <> True then begin Image4.Visible := true; Image9.Visible := false; Image11.Visible := false; Image7.Visible := false; Image5.Visible := false; Image2.Visible := true; Image8.Visible := true; Image10.Visible := true; Image6.Visible := true; Image3.Visible := true; Image12.Visible := true; Image13.Visible := false; Image14.Visible := false; semafor_pic1 := true; semafor_pic2 := false; semafor_pic3 := false; semafor_pic4 := false; semafor_pic5 := false; end; end; procedure TForm1.Image6MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if semafor_pic3 <> True then begin Image4.Visible := false; Image9.Visible := false; Image11.Visible := false; Image7.Visible := true; Image5.Visible := false; Image2.Visible := true; Image8.Visible := true; Image10.Visible := true; Image6.Visible := true; Image3.Visible := true; Image12.Visible := false; Image13.Visible := false; Image14.Visible := false; semafor_pic1 := false; semafor_pic2 := false; semafor_pic3 := true; semafor_pic4 := false; semafor_pic5 := false; end; end; procedure TForm1.Image3MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if semafor_pic2 <> True then begin Image4.Visible := false; Image9.Visible := false; Image11.Visible := false; Image7.Visible := false; Image5.Visible := true; Image2.Visible := true; Image8.Visible := true; Image10.Visible := true; Image6.Visible := true; Image3.Visible := true; Image12.Visible := false; Image13.Visible := false; Image14.Visible := false; semafor_pic1 := false; semafor_pic2 := true; semafor_pic3 := false; semafor_pic4 := false; semafor_pic5 := false; end; end; procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if semafor_pic1 <> false then begin Image4.Visible := false; Image9.Visible := false; Image11.Visible := false; Image7.Visible := false; Image5.Visible := false; Image2.Visible := true; Image8.Visible := true; Image10.Visible := true; Image6.Visible := true; Image3.Visible := true; Image12.Visible := false; Image13.Visible := false; Image14.Visible := false; semafor_pic1 := false; semafor_pic2 := false; semafor_pic3 := false; semafor_pic4 := false; semafor_pic5 := false; end; if semafor_pic2 <> false then begin Image4.Visible := false; Image9.Visible := false; Image11.Visible := false; Image7.Visible := false; Image5.Visible := false; Image2.Visible := true; Image8.Visible := true; Image10.Visible := true; Image6.Visible := true; Image3.Visible := true; Image12.Visible := false; Image13.Visible := false; Image14.Visible := false; semafor_pic1 := false; semafor_pic2 := false; semafor_pic3 := false; semafor_pic4 := false; semafor_pic5 := false; end; if semafor_pic3 <> false then begin Image4.Visible := false; Image9.Visible := false; Image11.Visible := false; Image7.Visible := false; Image5.Visible := false; Image2.Visible := true; Image8.Visible := true; Image10.Visible := true; Image6.Visible := true; Image3.Visible := true; Image12.Visible := false; Image13.Visible := false; Image14.Visible := false; semafor_pic1 := false; semafor_pic2 := false; semafor_pic3 := false; semafor_pic4 := false; semafor_pic5 := false; end; if semafor_pic4 <> false then begin Image4.Visible := false; Image9.Visible := false; Image11.Visible := false; Image7.Visible := false; Image5.Visible := false; Image2.Visible := true; Image8.Visible := true; Image10.Visible := true; Image6.Visible := true; Image3.Visible := true; Image12.Visible := false; Image13.Visible := false; Image14.Visible := false; semafor_pic1 := false; semafor_pic2 := false; semafor_pic3 := false; semafor_pic4 := false; semafor_pic5 := false; end; if semafor_pic5 <> false then begin Image4.Visible := false; Image9.Visible := false; Image11.Visible := false; Image7.Visible := false; Image5.Visible := false; Image2.Visible := true; Image8.Visible := true; Image10.Visible := true; Image6.Visible := true; Image3.Visible := true; Image12.Visible := false; Image13.Visible := false; Image14.Visible := false; semafor_pic1 := false; semafor_pic2 := false; semafor_pic3 := false; semafor_pic4 := false; semafor_pic5 := false; end; end; procedure TForm1.Image8MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if semafor_pic4 <> true then begin Image4.Visible := false; Image9.Visible := true; Image11.Visible := false; Image7.Visible := false; Image5.Visible := false; Image2.Visible := true; Image8.Visible := true; Image10.Visible := true; Image6.Visible := true; Image3.Visible := true; Image12.Visible := false; Image13.Visible := true; Image14.Visible := false; semafor_pic1 := false; semafor_pic2 := true; semafor_pic3 := false; semafor_pic4 := false; semafor_pic5 := false; end; end; procedure TForm1.Image10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if semafor_pic5 <> true then begin Image4.Visible := false; Image9.Visible := false; Image11.Visible := true; Image7.Visible := false; Image5.Visible := false; Image2.Visible := true; Image8.Visible := true; Image10.Visible := true; Image6.Visible := true; Image3.Visible := true; Image12.Visible := false; Image13.Visible := false; Image14.Visible := true; semafor_pic1 := false; semafor_pic2 := false; semafor_pic3 := false; semafor_pic4 := false; semafor_pic5 := true; end; end; procedure TForm1.FormCreate(Sender: TObject); begin semafor_pic1 := true; semafor_pic2 := false; semafor_pic3 := false; semafor_pic4 := false; semafor_pic5 := false; end;
"Blame it on my inexperience, but it seemed like a simpler solution was a bit more appropriate. When I had to modify one of the projects, I changed the above logic to the following."
procedure TForm2.ImageMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer); var t : integer; begin // glow "buttons" t := TImage(Sender).Tag; Image4.Visible := t = 1; // first button glow Image9.Visible := t = 2; // second button glow Image11.Visible := t = 3; // third button glow Image7.Visible := t = 4; // fourth button glow Image5.Visible := t = 5; // fifth button glow // show photos when hover first three buttons Image12.Visible := t = 1; // stock photo1 Image13.Visible := t = 2; // stock photo2 Image14.Visible := t = 3; // stock photo3 end;
Derek added, "unsurprisingly, the original author was not too impressed. 'Phmph,' he grumbled, 'my way worked fine, too.' It was a pretty good lesson to learn."