Solved

Memos and things

Posted on 2002-03-19
3
142 Views
Last Modified: 2011-09-20
I have a case statement to deal with printing reports - This bit is fine.

I want to describe the report to users and I am using a Tmemo to do this.

So I have something like


radiogroup1.index of

0: begin
Fillthememocase0;
othercode;
end;
1: begin
fillthememocase1;
othercode;
end;
2: begin
fillthememocase2;
othercode;
end;
3: begin
fillthememocase3;
othercode;
end;
end;

etc,etc,etc,


I can clearly fillthememo by using memo1.lines.add('bumph');


I feel sure that there must be a tidier way.

Can I please have some thoughts on tidying this up.

This isn't a question of not being able to cope - This is a question of readability of code;

TVMIA

Regards John

0
Comment
Question by:jbeh
3 Comments
 
LVL 6

Accepted Solution

by:
Stuart_Johnson earned 50 total points
ID: 6881669
Hi John,

The way I would do this is like this:

procedure TForm1.FillMemo;
const
  MemoLines: Array[0..3] of String = ('This is comment1',
    'This is comment2', 'This is comment3',
    'This is comment4');
begin
  Memo1.Lines.Text := MemoLines[RadioGroup1.Index];
  othercode;
end;

If you need to do multiple lines (example):

This is my first report.

It is really good.

You'd do the following:

  MemoLines: Array[0..3] of String = ('This is my first report' + #13 + 'It is really good.',
  'This is comment2','This is comment3',
  'This is comment4');

I hope this helps,

Cheers,

Stu.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6881890
whats wrong with this,
it seems ok to me,
specially that you've also
othercode in each case

more readability you can get with comment-lines,
where you could describe what this case do

meikl ;-)
0
 

Author Comment

by:jbeh
ID: 6882196
Looks good to me -

All this means is that I can now shuffle acres of commentary somewhere else so that I can still read my case statement sensibly -

Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now