Solved

A String Thing

Posted on 1998-12-18
2
146 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
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

22 Experts available now in Live!

Get 1:1 Help Now