Recent

Author Topic: Effective code writing  (Read 2737 times)

tomino

  • New Member
  • *
  • Posts: 28
Effective code writing
« on: April 24, 2014, 04:00:36 pm »
memo1.lines.append('text1');
memo1.lines.append('text2');
memo1.lines.append('text3');
memo1.lines.append('text4');
memo1.lines.append('text5');
you can see in my opinion uneffective programming how could i write this efectliveli ? i mean can i write something like this ?

for memo1.lines.append do
begin
('text1');
('text2');
('text3');
('text4');
('text5');
end;

or how could i do it in inteligent way ?
« Last Edit: April 24, 2014, 04:02:11 pm by tomino »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Effective code writing
« Reply #1 on: April 24, 2014, 04:11:43 pm »
Hi,
Code: [Select]
with Memo1.Lines do
  begin
    Append('rtzui');
    Append('ertgh');
  end;
or
Code: [Select]
const cText: array[0..3] of string = ('wer', 'wert', 'edf', 'wesd');
....
var i: Integer;
....
for i:=0 to high(cText) do
  Memo1.Lines.Append(cText[i]);
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

dpremus

  • New Member
  • *
  • Posts: 32
Re: Effective code writing
« Reply #2 on: April 24, 2014, 04:27:41 pm »
you can write code like this:

const LF = #10;

memo1.lines.add('abc' + LF + 'bce' + LF  + 'dde');     

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Effective code writing
« Reply #3 on: April 24, 2014, 04:31:44 pm »
Two things worth mentioning:
1-If you already know the text you want to add to Memo1 during program design time, then you could use Object Inspector and add these lines using Strings Editor Dialog.

2-If the number of lines (words in your example) is big, you should consider storing them in a text file and using:
Code: [Select]
  Memo1.Lines.LoadFromFile('path-to-your-txt-file');

Mando

  • Full Member
  • ***
  • Posts: 181
Re: Effective code writing
« Reply #4 on: April 24, 2014, 05:29:03 pm »
Hello:


Try this
Code: [Select]
  Memo1.Lines.commaText:='text1,text2,text3,text4';


And If you want to preserve the old content:

Code: [Select]
  Memo1.Lines.commaText:=Memo1.lines.commaText+',text1,text2,text3,text4';




regards

 

TinyPortal © 2005-2018