Solved

A String Thing

Posted on 1998-12-18
2
153 Views
Last Modified: 2010-04-04
I am still in the early learning stages of Delphi(4) and have been experimenting with using a Common Unit(no form) that other units(with forms) can feed from. I'm trying to set something up where a Label Caption is set within the Common Unit and under certain conditions will show in designated labels on other forms. Any help? This is what I have so far:

{this is Unit2, my common unit}
procedure TryOut(Trial: boolean; TheLabel: TLabel; Cap: string);
begin
TheLabel.Caption := Cap;
if Trial = True then
Cap := 'True' else
Cap := 'False';
end;

{This is one of my Units(with Form)}
procedure TForm1.FormCreate(Sender: TObject);
begin
TryOut(True, Label1, Cap);
end;

If TryOut is set to True I want Label1.Caption as 'True'. On FormCreate Cap shows as an 'Undeclared Identifier'. How can I overcome this, bearing in mind I want the caption to come from the Common Unit.

PS Sorry for low points but almost bankrupt.
0
Comment
Question by:xpher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 20 total points
ID: 1351842
You have described two independant things you want to do:

1. Place a caption in a label given that the caption is defined in some other unit.
2. Place a caption of 'true' or 'false' in a label given an appropriate flag.


For option 1 rewrite you code like this:

Unit Common;

const
  TheCaption = 'The caption';

end.

{this is Unit2, my common unit}
    procedure TryOut(TheLabel: TLabel);
    begin
    TheLabel.Caption := TheCaption;
    end;

    {This is one of my Units(with Form)}
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    TryOut(Label1);
    end;

For option 2 rewrite you code like this:

{this is Unit2, my common unit}
    procedure TryOut(Trial: boolean; TheLabel: TLabel);
    begin
    if Trial = True then
    TheLabel.Caption:= 'True' else
    TheLabel.Caption:= 'False';
    end;

    {This is one of my Units(with Form)}
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    TryOut(True, Label1);
    end;

If i have missed something here perhaps could could give me some more details of exactly what you want to do.

Cheers,

Raymond.
0
 
LVL 1

Author Comment

by:xpher
ID: 1351843
Thanks for prompt and excellent reply.
Works great, I used option 2.

Cheers
Chris :))
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 124
How to define IfThen functions in one common unit? 4 79
Controlled Assessment GCSE - desperate help needed 4 121
Delphi Yen format 3 75
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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