Forum > Beginners

Training program

(1/2) > >>

pascal111:
I'm training as a beginner and typed this Arabic small program, and I think it can be typed better than what I did, what do you think I have missed in this code?:

https://github.com/pascal111-fra/Lazarus-programs/blob/main/example1/unit1.pas

Complete project is in:
https://github.com/pascal111-fra/Lazarus-programs/tree/main/example1

pascal111:
Ok! no answer, I think I need to specify a particular point. I saw before a way to gather some similar procedures in one procedure, it was using a sort of arrays or something like that, so how we can reduce the next procedures in just one procedure:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.CheckBox1Change(Sender: TObject);begin   if (checkbox1.Checked) then  inc(attrib_count)  else  dec(attrib_count); end;  procedure TForm1.CheckBox2Change(Sender: TObject);begin  if (checkbox2.Checked) then  inc(attrib_count)  else  dec(attrib_count);end; procedure TForm1.CheckBox3Change(Sender: TObject);begin  if (checkbox3.Checked) then  inc(attrib_count)  else  dec(attrib_count);end; procedure TForm1.CheckBox4Change(Sender: TObject);begin  if (checkbox4.Checked) then  inc(attrib_count)  else  dec(attrib_count);end; procedure TForm1.CheckBox5Change(Sender: TObject);begin  if (checkbox5.Checked) then  inc(attrib_count)  else  dec(attrib_count);end; 

marcov:
Let any such checkbox point to code like below:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.CheckBox1Change(Sender: TObject);begin  if sender is TCheckbox then   begin     if TCheckbox(sender).Checked then       inc(attrib_count)    else      dec(attrib_count);   end;end;
Let anyprocedure TForm1.CheckBox1Change(Sender: TObject);

Seenkao:

--- Quote from: marcov on June 29, 2022, 01:14:34 pm ---Let any such checkbox point to code like below:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.CheckBox1Change(Sender: TObject);begin  if sender is TCheckbox then   begin     if TCheckbox(sender).Checked then       inc(attrib_count)    else      dec(attrib_count);   end;end;
Let anyprocedure TForm1.CheckBox1Change(Sender: TObject);

--- End quote ---
И именно эту процедуру задайте каждому компоненту CheckBox. Не дублируйте!
Events -> OnChange -> выбрать нужную процедуру.

Eng:And it is this procedure that you set for each CheckBox component. Don't duplicate!
Events -> OnChange -> select the desired procedure.

pascal111:
Great! guys. It works fine, but what if I would like to change this procedure name "TForm1.CheckBox1Change" to more general name. You know "TForm1.CheckBox1Change" name is like if it's for "CheckBox1Change" only?

Navigation

[0] Message Index

[#] Next page

Go to full version