Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

A String Thing

Posted on 1998-12-18
2
Medium Priority
?
155 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 80 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

730 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